Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakeWeb changes the Net::HTTP behavior of a request with a block that calls #read_body on the response #18

Open
myronmarston opened this issue Sep 8, 2010 · 0 comments

Comments

@myronmarston
Copy link
Contributor

Given this ruby script:

require 'net/http'
require 'rubygems'

def perform_test
  response = Net::HTTP.new('example.com', 80).request_get('/') { |r| r.read_body { } }
  puts "  " + response.body.class.to_s
end

puts "Without FakeWeb loaded: "
perform_test

require 'fakeweb'
FakeWeb.allow_net_connect = true
puts "With FakeWeb loaded, and http connections allowed: "
perform_test

FakeWeb.register_uri(:get, 'http://example.com/', :body => 'body')
puts "With a stubbed request: "
perform_test

I get this output:

$ ruby fakeweb_example.rb 
Without FakeWeb loaded: 
  Net::ReadAdapter
With FakeWeb loaded, and http connections allowed: 
  Net::ReadAdapter
With a stubbed request: 
  String

As you can see, Net::HTTP causes the body of a response for a request with a block that calls #read_body to be a Net::ReadAdapter, but FakeWeb modifies this behavior when stubbing a request. FakeWeb causes it to be a String.

I've got a fix for this bug here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant