Skip to content

Commit

Permalink
Ensure the request body gets recorded with FakeWeb/Net::HTTP.
Browse files Browse the repository at this point in the history
For some reason, Net::HTTP provides `request_body` (passed as an extra argument) and `request.body` on the request argument...and sometimes the request body is on one or the other.

Closes vcr#127.
  • Loading branch information
myronmarston committed Jan 27, 2012
1 parent d61b66f commit 907b7bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vcr/library_hooks/fakeweb.rb
Expand Up @@ -113,7 +113,7 @@ def vcr_request
@vcr_request ||= VCR::Request.new \
request.method.downcase.to_sym,
uri,
request_body,
(request_body || request.body),
request.to_hash
end

Expand Down
9 changes: 9 additions & 0 deletions spec/vcr/library_hooks/fakeweb_spec.rb
Expand Up @@ -48,6 +48,15 @@ def directly_stub_request(method, url, response_body)
VCR.stub(:real_http_connections_allowed? => true)
end

it 'records the request body when using #post_form' do
VCR.should_receive(:record_http_interaction) do |interaction|
interaction.request.body.should eq("q=ruby&max=50")
end

uri = URI("http://localhost:#{VCR::SinatraApp.port}/foo")
Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50')
end

it "does not record headers for which Net::HTTP sets defaults near the end of the real request" do
VCR.should_receive(:record_http_interaction) do |interaction|
interaction.request.headers.should_not have_key('content-type')
Expand Down

0 comments on commit 907b7bc

Please sign in to comment.