fakeweb
fakeweb copied to clipboard
FakeWeb changes the Net::HTTP behavior of a request with a block that calls #read_body on the response
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.