Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure the methods in our fake match the user's version of Net::HTTP

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...
commit 48208f9bf053577befe5723746b6ff35b99b45d0 1 parent fb099ad
@chrisk authored
Showing with 18 additions and 1 deletion.
  1. +3 −1 lib/fake_web/stub_socket.rb
  2. +15 −0 test/test_timeouts.rb
View
4 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
View
15 test/test_timeouts.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.