Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Return nil when the body is stubbed as '' or nil.

When a real Net::HTTP request is made and receives an
empty-body response (such as a 204 No Content), then the
response body is nil.

This gist demonstrates the behavior:
https://gist.github.com/2918173
  • Loading branch information...
commit 6b2075fae1aba2d2f23d60406c8e7d1e817b85d9 1 parent 81524c1
@myronmarston authored
Showing with 9 additions and 2 deletions.
  1. +2 −1  lib/fake_web/responder.rb
  2. +7 −1 test/test_fake_web.rb
View
3  lib/fake_web/responder.rb
@@ -52,7 +52,8 @@ def headers_extracted_from_options
def body
body = options[:body]
- return "" if body.nil?
+ return nil if body.to_s == ''
+
body = body.to_s if defined?(Pathname) && body.is_a?(Pathname)
if !body.include?("\0") && File.exists?(body) && !File.directory?(body)
View
8 test/test_fake_web.rb
@@ -357,7 +357,13 @@ def test_register_unimplemented_response
def test_specifying_nil_for_body
FakeWeb.register_uri(:head, "http://example.com", :body => nil)
response = Net::HTTP.start("example.com") { |query| query.head("/") }
- assert_equal "", response.body
+ assert_equal nil, response.body
+ end
+
+ def test_specifying_empty_string_for_body
+ FakeWeb.register_uri(:head, "http://example.com", :body => '')
+ response = Net::HTTP.start("example.com") { |query| query.head("/") }
+ assert_equal nil, response.body
end
def test_real_http_request
Please sign in to comment.
Something went wrong with that request. Please try again.