Permalink
Browse files

Merge branch myronmarston/nil_response_body, closing #32

* myronmarston/nil_response_body:
  Return nil when the body is stubbed as '' or nil.

Conflicts:
	test/test_fake_web.rb
  • Loading branch information...
2 parents 97232ca + 6b2075f commit 2d47f83fdeb4f07d6fef72ef6f07c28f59277ab1 @chrisk committed May 15, 2013
Showing with 9 additions and 2 deletions.
  1. +2 −1 lib/fake_web/responder.rb
  2. +7 −1 test/test_fake_web.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
@@ -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_empty 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

0 comments on commit 2d47f83

Please sign in to comment.