Skip to content

Commit

Permalink
Make sure the methods in our fake match the user's version of Net::HTTP
Browse files Browse the repository at this point in the history
Specifically, this ensures that we won't add #continue_timeout= to rubies
that don't have it -- it was added to Net::HTTP in 1.9.3.
  • Loading branch information
chrisk committed Dec 2, 2013
1 parent fb099ad commit 48208f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/fake_web/stub_socket.rb
@@ -1,7 +1,9 @@
module FakeWeb
class StubSocket #:nodoc:

attr_accessor :read_timeout, :continue_timeout
Net::BufferedIO.instance_methods.grep(/_timeout$/).each do |timeout|
attr_accessor timeout
end

def initialize(*args)
end
Expand Down
15 changes: 15 additions & 0 deletions test/test_timeouts.rb
Expand Up @@ -15,4 +15,19 @@ def test_sending_timeout_accessors_after_starting_session
end
assert_equal [5], timeouts.uniq
end

def test_stub_socket_always_responds_to_read_timeout
FakeWeb.register_uri(:get, "http://example.com", :status => [200, "OK"])
http = Net::HTTP.new("example.com", 80)
http.get("/")
assert_respond_to http.instance_variable_get(:@socket), :read_timeout=
end

def test_stub_socket_only_responds_to_continue_timeout_under_193_or_later
FakeWeb.register_uri(:get, "http://example.com", :status => [200, "OK"])
http = Net::HTTP.new("example.com", 80)
http.get("/")
socket = http.instance_variable_get(:@socket)
assert_equal RUBY_VERSION >= "1.9.3", socket.respond_to?(:continue_timeout=)
end
end

0 comments on commit 48208f9

Please sign in to comment.