Permalink
Browse files

Fix implementation, add a test, and add docs for 0d69c71

  • Loading branch information...
1 parent 151723b commit 48c61c6700ab0e7cb608dc6d4bd8f464554c8ea8 @chrisk committed Aug 29, 2011
Showing with 10 additions and 3 deletions.
  1. +2 −2 lib/fake_web.rb
  2. +1 −1 lib/fake_web/responder.rb
  3. +7 −0 test/test_registering_with_io.rb
View
@@ -95,8 +95,8 @@ class MultipleMatchingURIsError < StandardError; end;
# as the body of the response instead. (This used to be two options,
# <tt>:string</tt> and <tt>:file</tt>, respectively. These are now deprecated.)
# <tt>:response</tt>::
- # Either a <tt>Net::HTTPResponse</tt>, an +IO+, or a +String+ which is used
- # as the full response for the request.
+ # Either a <tt>Net::HTTPResponse</tt>, +IO+, +StringIO+, or +String+, which
+ # is used as the full response for the request.
#
# The easier way by far is to pass the <tt>:response</tt> option to
# +register_uri+ as a +String+ or an (open for reads) +IO+ object which
@@ -66,7 +66,7 @@ def baked_response
response = options[:response]
response = response.to_s if defined?(Pathname) && response.is_a?(Pathname)
- if response.is_a?(String) || response.is_a?(IO)
+ if response.is_a?(String) || response.is_a?(IO) || response.is_a?(StringIO)
socket = Net::BufferedIO.new(response)
r = Net::HTTPResponse.read_new(socket)
@@ -23,4 +23,11 @@ def test_registering_a_file_handle_from_curl
assert response.body.include?("<title>Google</title>")
end
+ def test_registering_a_stringio
+ stringio = StringIO.new(File.read(fixture_path("google_response_from_curl")))
+ FakeWeb.register_uri(:get, "http://google.com", :response => stringio)
+ response = Net::HTTP.start("google.com") { |query| query.get('/') }
+ assert response.body.include?("<title>Google</title>")
+ end
+
end

0 comments on commit 48c61c6

Please sign in to comment.