Skip to content

Commit

Permalink
Added request body and headers to recorded response. These will come …
Browse files Browse the repository at this point in the history
…in handy for getting VCR to work with webmock.
  • Loading branch information
myronmarston committed Apr 11, 2010
1 parent 323d72d commit 7003176
Show file tree
Hide file tree
Showing 22 changed files with 221 additions and 29 deletions.
Expand Up @@ -41,3 +41,10 @@
message: OK
read: true
socket:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -21,6 +21,13 @@
message: Not Found
read: true
socket:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
method: :get
uri: http://example.com:80/after_nested
Expand All @@ -43,3 +50,10 @@
message: Not Found
read: true
socket:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -41,6 +41,13 @@
message: OK
read: true
socket:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
method: :get
uri: http://example.com:80/
Expand Down Expand Up @@ -83,3 +90,10 @@
message: OK
read: true
socket:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -21,3 +21,10 @@
message: Not Found
read: true
socket:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -41,3 +41,10 @@
message: OK
read: true
socket:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -41,3 +41,11 @@
message: OK
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -43,3 +43,11 @@
message: Not Found
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -83,3 +83,11 @@
message: OK
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -21,3 +21,11 @@
message: Not Found
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -41,3 +41,11 @@
message: OK
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -41,3 +41,11 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -29,6 +29,14 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
:method: :get
:uri: http://example.com:80/after_nested
Expand Down Expand Up @@ -59,3 +67,11 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -41,6 +41,14 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
:method: :get
:uri: http://example.com:80/
Expand Down Expand Up @@ -83,3 +91,11 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -28,4 +28,12 @@
http_version: "1.1"
message: OK
read: true
socket:
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
Expand Up @@ -41,3 +41,11 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
2 changes: 1 addition & 1 deletion lib/vcr/extensions/net_http.rb
Expand Up @@ -44,7 +44,7 @@ def __store_response_with_vcr__(response, request)
method = request.method.downcase.to_sym

unless FakeWeb.registered_uri?(method, uri)
cassette.store_recorded_response!(VCR::RecordedResponse.new(method, uri, response))
cassette.store_recorded_response!(VCR::RecordedResponse.new(method, uri, response, request.body, request.to_hash))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vcr/recorded_response.rb
@@ -1,4 +1,4 @@
module VCR
class RecordedResponse < Struct.new(:method, :uri, :response)
class RecordedResponse < Struct.new(:method, :uri, :response, :request_body, :request_headers)
end
end
2 changes: 1 addition & 1 deletion spec/extensions/net_http_spec.rb
Expand Up @@ -25,7 +25,7 @@ def perform_get_with_returning_block

it 'calls #store_recorded_response! on the current cassette' do
recorded_response = VCR::RecordedResponse.new(:get, 'http://example.com:80/', :example_response)
VCR::RecordedResponse.should_receive(:new).with(:get, 'http://example.com:80/', an_instance_of(Net::HTTPOK)).and_return(recorded_response)
VCR::RecordedResponse.should_receive(:new).with(:get, 'http://example.com:80/', an_instance_of(Net::HTTPOK), anything, anything).and_return(recorded_response)
@current_cassette.should_receive(:store_recorded_response!).with(recorded_response)
Net::HTTP.get(@uri)
end
Expand Down
24 changes: 24 additions & 0 deletions spec/fixtures/1.8.6/cassette_spec/example.yml
Expand Up @@ -44,6 +44,14 @@
message: OK
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
method: :get
uri: http://example.com:80/foo
Expand Down Expand Up @@ -76,6 +84,14 @@
message: Not Found
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
method: :get
uri: http://example.com:80/
Expand Down Expand Up @@ -106,3 +122,11 @@
message: OK
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
24 changes: 24 additions & 0 deletions spec/fixtures/1.8.7/cassette_spec/example.yml
Expand Up @@ -44,6 +44,14 @@
message: OK
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
method: :get
uri: http://example.com:80/foo
Expand Down Expand Up @@ -76,6 +84,14 @@
message: Not Found
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
method: :get
uri: http://example.com:80/
Expand Down Expand Up @@ -106,3 +122,11 @@
message: OK
read: true
socket:
request_body:
request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
24 changes: 24 additions & 0 deletions spec/fixtures/1.9.1/cassette_spec/example.yml
Expand Up @@ -43,6 +43,14 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
:method: :get
:uri: http://example.com:80/foo
Expand Down Expand Up @@ -75,6 +83,14 @@
message: Not Found
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com
- !ruby/struct:VCR::RecordedResponse
:method: :get
:uri: http://example.com:80/
Expand Down Expand Up @@ -105,3 +121,11 @@
message: OK
read: true
socket:
:request_body:
:request_headers:
accept:
- "*/*"
connection:
- close
host:
- example.com

0 comments on commit 7003176

Please sign in to comment.