vcr 1.11.3 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +6 -2
- data/CHANGELOG.md +49 -1
- data/Gemfile +1 -5
- data/Guardfile +0 -5
- data/README.md +3 -2
- data/Rakefile +11 -16
- data/cucumber.yml +0 -4
- data/features/.nav +14 -2
- data/features/cassettes/automatic_re_recording.feature +4 -6
- data/features/cassettes/dynamic_erb.feature +6 -8
- data/features/cassettes/exclusive.feature +111 -0
- data/features/cassettes/format.feature +16 -14
- data/features/cassettes/naming.feature +4 -6
- data/features/cassettes/no_cassette.feature +25 -28
- data/features/cassettes/update_content_length_header.feature +9 -9
- data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -8
- data/features/configuration/cassette_library_dir.feature +4 -6
- data/features/configuration/default_cassette_options.feature +12 -10
- data/features/configuration/filter_sensitive_data.feature +12 -17
- data/features/configuration/{stub_with.feature → hook_into.feature} +63 -62
- data/features/configuration/hooks.feature +23 -33
- data/features/configuration/ignore_hosts.feature +16 -17
- data/features/configuration/ignore_localhost.feature +33 -42
- data/features/http_libraries/em_http_request.feature +7 -8
- data/features/http_libraries/net_http.feature +26 -28
- data/features/middleware/faraday.feature +17 -56
- data/features/middleware/rack.feature +8 -11
- data/features/record_modes/all.feature +5 -7
- data/features/record_modes/new_episodes.feature +5 -7
- data/features/record_modes/none.feature +6 -6
- data/features/record_modes/once.feature +6 -8
- data/features/request_matching/README.md +28 -0
- data/features/request_matching/body.feature +81 -0
- data/features/request_matching/custom_matcher.feature +125 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +85 -0
- data/features/request_matching/identical_request_sequence.feature +79 -0
- data/features/request_matching/method.feature +86 -0
- data/features/request_matching/path.feature +86 -0
- data/features/request_matching/playback_repeats.feature +87 -0
- data/features/request_matching/uri.feature +84 -0
- data/features/request_matching/uri_without_param.feature +85 -0
- data/features/step_definitions/cli_steps.rb +4 -28
- data/features/support/env.rb +11 -9
- data/features/support/http_lib_filters.rb +2 -11
- data/features/support/vcr_cucumber_helpers.rb +4 -5
- data/features/test_frameworks/cucumber.feature +17 -18
- data/features/test_frameworks/rspec.feature +8 -12
- data/features/test_frameworks/shoulda.feature +5 -8
- data/features/test_frameworks/test_unit.feature +5 -8
- data/lib/vcr.rb +38 -58
- data/lib/vcr/cassette.rb +41 -60
- data/lib/vcr/cassette/http_interaction_list.rb +56 -0
- data/lib/vcr/cassette/reader.rb +29 -31
- data/lib/vcr/configuration.rb +76 -0
- data/lib/vcr/deprecations.rb +39 -0
- data/lib/vcr/errors.rb +22 -0
- data/lib/vcr/library_hooks.rb +19 -0
- data/lib/vcr/library_hooks/excon.rb +136 -0
- data/lib/vcr/library_hooks/fakeweb.rb +110 -0
- data/lib/vcr/library_hooks/faraday.rb +3 -0
- data/lib/vcr/library_hooks/typhoeus.rb +98 -0
- data/lib/vcr/library_hooks/webmock.rb +100 -0
- data/lib/vcr/middleware/faraday.rb +43 -36
- data/lib/vcr/middleware/rack.rb +28 -4
- data/lib/vcr/request_handler.rb +43 -0
- data/lib/vcr/request_ignorer.rb +31 -0
- data/lib/vcr/request_matcher_registry.rb +86 -0
- data/lib/vcr/structs/http_interaction.rb +24 -18
- data/lib/vcr/structs/normalizers/body.rb +1 -1
- data/lib/vcr/structs/normalizers/header.rb +1 -1
- data/lib/vcr/structs/normalizers/status_message.rb +1 -1
- data/lib/vcr/structs/normalizers/uri.rb +1 -1
- data/lib/vcr/structs/request.rb +0 -13
- data/lib/vcr/structs/response.rb +2 -9
- data/lib/vcr/structs/response_status.rb +0 -4
- data/lib/vcr/test_frameworks/cucumber.rb +1 -1
- data/lib/vcr/test_frameworks/rspec.rb +1 -1
- data/lib/vcr/util/hooks.rb +28 -19
- data/lib/vcr/util/internet_connection.rb +29 -2
- data/lib/vcr/util/version_checker.rb +60 -0
- data/lib/vcr/version.rb +1 -1
- data/script/FullBuildRakeFile +0 -7
- data/script/full_build +1 -1
- data/spec/capture_warnings.rb +36 -31
- data/spec/fixtures/{1.9.1/cassette_spec → cassette_spec}/empty.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/example.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/with_localhost_requests.yml +0 -0
- data/spec/fixtures/{not_1.9.1/fake_example.com_responses.yml → fake_example.com_responses.yml} +0 -0
- data/spec/fixtures/{not_1.9.1/match_requests_on.yml → match_requests_on.yml} +0 -0
- data/spec/monkey_patches.rb +40 -11
- data/spec/spec_helper.rb +7 -43
- data/spec/support/http_library_adapters.rb +3 -13
- data/spec/support/shared_example_groups/{http_library.rb → hook_into_http_library.rb} +39 -111
- data/spec/support/shared_example_groups/version_checking.rb +9 -9
- data/spec/vcr/cassette/http_interaction_list_spec.rb +178 -0
- data/spec/vcr/cassette/reader_spec.rb +2 -2
- data/spec/vcr/cassette_spec.rb +121 -156
- data/spec/vcr/configuration_spec.rb +143 -0
- data/spec/vcr/deprecations_spec.rb +91 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/excon_spec.rb +6 -9
- data/spec/vcr/library_hooks/fakeweb_spec.rb +83 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/typhoeus_spec.rb +7 -11
- data/spec/vcr/library_hooks/webmock_spec.rb +17 -0
- data/spec/vcr/library_hooks_spec.rb +51 -0
- data/spec/vcr/middleware/faraday_spec.rb +17 -44
- data/spec/vcr/middleware/rack_spec.rb +94 -58
- data/spec/vcr/request_ignorer_spec.rb +54 -0
- data/spec/vcr/request_matcher_registry_spec.rb +223 -0
- data/spec/vcr/structs/request_spec.rb +0 -33
- data/spec/vcr/structs/response_spec.rb +0 -24
- data/spec/vcr/structs/response_status_spec.rb +0 -9
- data/spec/vcr/util/hooks_spec.rb +3 -5
- data/spec/vcr/version_spec.rb +1 -1
- data/spec/vcr_spec.rb +79 -91
- data/vcr.gemspec +1 -1
- metadata +83 -103
- data/features/cassettes/request_matching.feature +0 -383
- data/lib/vcr/config.rb +0 -84
- data/lib/vcr/deprecations/cassette.rb +0 -29
- data/lib/vcr/deprecations/config.rb +0 -18
- data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +0 -9
- data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +0 -11
- data/lib/vcr/extensions/net_http.rb +0 -32
- data/lib/vcr/http_stubbing_adapters/common.rb +0 -202
- data/lib/vcr/http_stubbing_adapters/excon.rb +0 -178
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -107
- data/lib/vcr/http_stubbing_adapters/faraday.rb +0 -26
- data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +0 -43
- data/lib/vcr/http_stubbing_adapters/typhoeus.rb +0 -115
- data/lib/vcr/http_stubbing_adapters/webmock.rb +0 -120
- data/lib/vcr/middleware/cassette_arguments.rb +0 -19
- data/lib/vcr/middleware/common.rb +0 -20
- data/lib/vcr/request_matcher.rb +0 -94
- data/lib/vcr/rspec.rb +0 -2
- data/lib/vcr/util/basic_object.rb +0 -43
- data/lib/vcr/util/ping.rb +0 -30
- data/lib/vcr/util/regexes.rb +0 -37
- data/spec/fixtures/1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/1.9.1/cassette_spec/example.yml +0 -110
- data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +0 -109
- data/spec/fixtures/1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/1.9.1/example_net_http_response.yml +0 -25
- data/spec/fixtures/1.9.1/fake_example.com_responses.yml +0 -108
- data/spec/fixtures/1.9.1/match_requests_on.yml +0 -185
- data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/not_1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/not_1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/not_1.9.1/example_net_http_response.yml +0 -25
- data/spec/support/shared_example_groups/http_stubbing_adapter.rb +0 -133
- data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +0 -28
- data/spec/vcr/config_spec.rb +0 -181
- data/spec/vcr/deprecations/cassette_spec.rb +0 -57
- data/spec/vcr/deprecations/config_spec.rb +0 -30
- data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +0 -7
- data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +0 -16
- data/spec/vcr/extensions/net_http_spec.rb +0 -80
- data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +0 -19
- data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +0 -76
- data/spec/vcr/http_stubbing_adapters/multi_object_proxy_spec.rb +0 -101
- data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +0 -17
- data/spec/vcr/middleware/cassette_arguments_spec.rb +0 -32
- data/spec/vcr/request_matcher_spec.rb +0 -230
@@ -0,0 +1,85 @@
|
|
1
|
+
Feature: Matching on Headers
|
2
|
+
|
3
|
+
Use the `:headers` request matcher to match requests on the request headers.
|
4
|
+
|
5
|
+
Background:
|
6
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
7
|
+
"""
|
8
|
+
---
|
9
|
+
- !ruby/struct:VCR::HTTPInteraction
|
10
|
+
request: !ruby/struct:VCR::Request
|
11
|
+
method: :post
|
12
|
+
uri: http://example.net:80/some/long/path
|
13
|
+
body:
|
14
|
+
headers:
|
15
|
+
x-user-id:
|
16
|
+
- "1"
|
17
|
+
response: !ruby/struct:VCR::Response
|
18
|
+
status: !ruby/struct:VCR::ResponseStatus
|
19
|
+
code: 200
|
20
|
+
message: OK
|
21
|
+
headers:
|
22
|
+
content-length:
|
23
|
+
- "15"
|
24
|
+
body: user 1 response
|
25
|
+
http_version: "1.1"
|
26
|
+
- !ruby/struct:VCR::HTTPInteraction
|
27
|
+
request: !ruby/struct:VCR::Request
|
28
|
+
method: :post
|
29
|
+
uri: http://example.net:80/some/long/path
|
30
|
+
body:
|
31
|
+
headers:
|
32
|
+
x-user-id:
|
33
|
+
- "2"
|
34
|
+
response: !ruby/struct:VCR::Response
|
35
|
+
status: !ruby/struct:VCR::ResponseStatus
|
36
|
+
code: 200
|
37
|
+
message: OK
|
38
|
+
headers:
|
39
|
+
content-length:
|
40
|
+
- "15"
|
41
|
+
body: user 2 response
|
42
|
+
http_version: "1.1"
|
43
|
+
"""
|
44
|
+
|
45
|
+
Scenario Outline: Replay interaction that matches the headers
|
46
|
+
And a file named "header_matching.rb" with:
|
47
|
+
"""ruby
|
48
|
+
include_http_adapter_for("<http_lib>")
|
49
|
+
|
50
|
+
require 'vcr'
|
51
|
+
|
52
|
+
VCR.configure do |c|
|
53
|
+
<configuration>
|
54
|
+
c.cassette_library_dir = 'cassettes'
|
55
|
+
end
|
56
|
+
|
57
|
+
VCR.use_cassette('example', :match_requests_on => [:headers]) do
|
58
|
+
puts "Response for user 2: " + response_body_for(:get, "http://example.com/", nil, 'X-User-Id' => '2')
|
59
|
+
end
|
60
|
+
|
61
|
+
VCR.use_cassette('example', :match_requests_on => [:headers]) do
|
62
|
+
puts "Response for user 1: " + response_body_for(:get, "http://example.com/", nil, 'X-User-Id' => '1')
|
63
|
+
end
|
64
|
+
"""
|
65
|
+
When I run `ruby header_matching.rb`
|
66
|
+
Then it should pass with:
|
67
|
+
"""
|
68
|
+
Response for user 2: user 2 response
|
69
|
+
Response for user 1: user 1 response
|
70
|
+
"""
|
71
|
+
|
72
|
+
Examples:
|
73
|
+
| configuration | http_lib |
|
74
|
+
| c.hook_into :fakeweb | net/http |
|
75
|
+
| c.hook_into :webmock | net/http |
|
76
|
+
| c.hook_into :webmock | httpclient |
|
77
|
+
| c.hook_into :webmock | curb |
|
78
|
+
| c.hook_into :webmock | patron |
|
79
|
+
| c.hook_into :webmock | em-http-request |
|
80
|
+
| c.hook_into :webmock | typhoeus |
|
81
|
+
| c.hook_into :typhoeus | typhoeus |
|
82
|
+
| c.hook_into :excon | excon |
|
83
|
+
| | faraday (w/ net_http) |
|
84
|
+
| | faraday (w/ typhoeus) |
|
85
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
Feature: Matching on Host
|
2
|
+
|
3
|
+
Use the `:host` request matcher to match requests on the request host.
|
4
|
+
|
5
|
+
You can use this (alone, or in combination with `:path`) as an
|
6
|
+
alternative to `:uri` so that non-deterministic portions of the URI
|
7
|
+
are not considered as part of the request matching.
|
8
|
+
|
9
|
+
Background:
|
10
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
11
|
+
"""
|
12
|
+
---
|
13
|
+
- !ruby/struct:VCR::HTTPInteraction
|
14
|
+
request: !ruby/struct:VCR::Request
|
15
|
+
method: :post
|
16
|
+
uri: http://host1.com:80/some/long/path
|
17
|
+
body:
|
18
|
+
headers:
|
19
|
+
response: !ruby/struct:VCR::Response
|
20
|
+
status: !ruby/struct:VCR::ResponseStatus
|
21
|
+
code: 200
|
22
|
+
message: OK
|
23
|
+
headers:
|
24
|
+
content-length:
|
25
|
+
- "14"
|
26
|
+
body: host1 response
|
27
|
+
http_version: "1.1"
|
28
|
+
- !ruby/struct:VCR::HTTPInteraction
|
29
|
+
request: !ruby/struct:VCR::Request
|
30
|
+
method: :post
|
31
|
+
uri: http://host2.com:80/some/other/long/path
|
32
|
+
body:
|
33
|
+
headers:
|
34
|
+
response: !ruby/struct:VCR::Response
|
35
|
+
status: !ruby/struct:VCR::ResponseStatus
|
36
|
+
code: 200
|
37
|
+
message: OK
|
38
|
+
headers:
|
39
|
+
content-length:
|
40
|
+
- "16"
|
41
|
+
body: host2 response
|
42
|
+
http_version: "1.1"
|
43
|
+
"""
|
44
|
+
|
45
|
+
Scenario Outline: Replay interaction that matches the host
|
46
|
+
And a file named "host_matching.rb" with:
|
47
|
+
"""ruby
|
48
|
+
include_http_adapter_for("<http_lib>")
|
49
|
+
|
50
|
+
require 'vcr'
|
51
|
+
|
52
|
+
VCR.configure do |c|
|
53
|
+
<configuration>
|
54
|
+
c.cassette_library_dir = 'cassettes'
|
55
|
+
end
|
56
|
+
|
57
|
+
VCR.use_cassette('example', :match_requests_on => [:host]) do
|
58
|
+
puts "Response for host2: " + response_body_for(:get, "http://host2.com/home")
|
59
|
+
end
|
60
|
+
|
61
|
+
VCR.use_cassette('example', :match_requests_on => [:host]) do
|
62
|
+
puts "Response for host1: " + response_body_for(:get, "http://host1.com/about")
|
63
|
+
end
|
64
|
+
"""
|
65
|
+
When I run `ruby host_matching.rb`
|
66
|
+
Then it should pass with:
|
67
|
+
"""
|
68
|
+
Response for host2: host2 response
|
69
|
+
Response for host1: host1 response
|
70
|
+
"""
|
71
|
+
|
72
|
+
Examples:
|
73
|
+
| configuration | http_lib |
|
74
|
+
| c.hook_into :fakeweb | net/http |
|
75
|
+
| c.hook_into :webmock | net/http |
|
76
|
+
| c.hook_into :webmock | httpclient |
|
77
|
+
| c.hook_into :webmock | curb |
|
78
|
+
| c.hook_into :webmock | patron |
|
79
|
+
| c.hook_into :webmock | em-http-request |
|
80
|
+
| c.hook_into :webmock | typhoeus |
|
81
|
+
| c.hook_into :typhoeus | typhoeus |
|
82
|
+
| c.hook_into :excon | excon |
|
83
|
+
| | faraday (w/ net_http) |
|
84
|
+
| | faraday (w/ typhoeus) |
|
85
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Feature: Identical requests are replayed in sequence
|
2
|
+
|
3
|
+
When a cassette contains multiple HTTP interactions that match a request
|
4
|
+
based on the configured `:match_requests_on` setting, the responses are
|
5
|
+
sequenced: the first matching request will get the first response,
|
6
|
+
the second matching request will get the second response, etc.
|
7
|
+
|
8
|
+
Scenario Outline: identical requests are replayed in sequence
|
9
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
10
|
+
"""
|
11
|
+
---
|
12
|
+
- !ruby/struct:VCR::HTTPInteraction
|
13
|
+
request: !ruby/struct:VCR::Request
|
14
|
+
method: :get
|
15
|
+
uri: http://example.com:80/foo
|
16
|
+
body:
|
17
|
+
headers:
|
18
|
+
response: !ruby/struct:VCR::Response
|
19
|
+
status: !ruby/struct:VCR::ResponseStatus
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
content-length:
|
24
|
+
- "10"
|
25
|
+
body: Response 1
|
26
|
+
http_version: "1.1"
|
27
|
+
- !ruby/struct:VCR::HTTPInteraction
|
28
|
+
request: !ruby/struct:VCR::Request
|
29
|
+
method: :get
|
30
|
+
uri: http://example.com:80/foo
|
31
|
+
body:
|
32
|
+
headers:
|
33
|
+
response: !ruby/struct:VCR::Response
|
34
|
+
status: !ruby/struct:VCR::ResponseStatus
|
35
|
+
code: 200
|
36
|
+
message: OK
|
37
|
+
headers:
|
38
|
+
content-length:
|
39
|
+
- "10"
|
40
|
+
body: Response 2
|
41
|
+
http_version: "1.1"
|
42
|
+
"""
|
43
|
+
And a file named "rotate_responses.rb" with:
|
44
|
+
"""ruby
|
45
|
+
include_http_adapter_for("<http_lib>")
|
46
|
+
|
47
|
+
require 'vcr'
|
48
|
+
|
49
|
+
VCR.configure do |c|
|
50
|
+
<configuration>
|
51
|
+
c.cassette_library_dir = 'cassettes'
|
52
|
+
end
|
53
|
+
|
54
|
+
VCR.use_cassette('example') do
|
55
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
56
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
57
|
+
end
|
58
|
+
"""
|
59
|
+
When I run `ruby rotate_responses.rb`
|
60
|
+
Then it should pass with:
|
61
|
+
"""
|
62
|
+
Response 1
|
63
|
+
Response 2
|
64
|
+
"""
|
65
|
+
|
66
|
+
Examples:
|
67
|
+
| configuration | http_lib |
|
68
|
+
| c.hook_into :fakeweb | net/http |
|
69
|
+
| c.hook_into :webmock | net/http |
|
70
|
+
| c.hook_into :webmock | httpclient |
|
71
|
+
| c.hook_into :webmock | curb |
|
72
|
+
| c.hook_into :webmock | patron |
|
73
|
+
| c.hook_into :webmock | em-http-request |
|
74
|
+
| c.hook_into :webmock | typhoeus |
|
75
|
+
| c.hook_into :typhoeus | typhoeus |
|
76
|
+
| c.hook_into :excon | excon |
|
77
|
+
| | faraday (w/ net_http) |
|
78
|
+
| | faraday (w/ typhoeus) |
|
79
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Feature: Matching on Method
|
2
|
+
|
3
|
+
Use the `:method` request matcher to match requests on the HTTP method
|
4
|
+
(i.e. GET, POST, PUT, DELETE, etc). You will generally want to use
|
5
|
+
this matcher.
|
6
|
+
|
7
|
+
The `:method` matcher is used (along with the `:uri` matcher) by default
|
8
|
+
if you do not specify how requests should match.
|
9
|
+
|
10
|
+
Background:
|
11
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
12
|
+
"""
|
13
|
+
---
|
14
|
+
- !ruby/struct:VCR::HTTPInteraction
|
15
|
+
request: !ruby/struct:VCR::Request
|
16
|
+
method: :post
|
17
|
+
uri: http://post-request.com:80/
|
18
|
+
body:
|
19
|
+
headers:
|
20
|
+
response: !ruby/struct:VCR::Response
|
21
|
+
status: !ruby/struct:VCR::ResponseStatus
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
content-length:
|
26
|
+
- "13"
|
27
|
+
body: post response
|
28
|
+
http_version: "1.1"
|
29
|
+
- !ruby/struct:VCR::HTTPInteraction
|
30
|
+
request: !ruby/struct:VCR::Request
|
31
|
+
method: :get
|
32
|
+
uri: http://get-request.com:80/
|
33
|
+
body:
|
34
|
+
headers:
|
35
|
+
response: !ruby/struct:VCR::Response
|
36
|
+
status: !ruby/struct:VCR::ResponseStatus
|
37
|
+
code: 200
|
38
|
+
message: OK
|
39
|
+
headers:
|
40
|
+
content-length:
|
41
|
+
- "12"
|
42
|
+
body: get response
|
43
|
+
http_version: "1.1"
|
44
|
+
"""
|
45
|
+
|
46
|
+
Scenario Outline: Replay interaction that matches the HTTP method
|
47
|
+
And a file named "method_matching.rb" with:
|
48
|
+
"""ruby
|
49
|
+
include_http_adapter_for("<http_lib>")
|
50
|
+
|
51
|
+
require 'vcr'
|
52
|
+
|
53
|
+
VCR.configure do |c|
|
54
|
+
<configuration>
|
55
|
+
c.cassette_library_dir = 'cassettes'
|
56
|
+
end
|
57
|
+
|
58
|
+
VCR.use_cassette('example', :match_requests_on => [:method]) do
|
59
|
+
puts "Response for GET: " + response_body_for(:get, "http://example.com/")
|
60
|
+
end
|
61
|
+
|
62
|
+
VCR.use_cassette('example', :match_requests_on => [:method]) do
|
63
|
+
puts "Response for POST: " + response_body_for(:post, "http://example.com/")
|
64
|
+
end
|
65
|
+
"""
|
66
|
+
When I run `ruby method_matching.rb`
|
67
|
+
Then it should pass with:
|
68
|
+
"""
|
69
|
+
Response for GET: get response
|
70
|
+
Response for POST: post response
|
71
|
+
"""
|
72
|
+
|
73
|
+
Examples:
|
74
|
+
| configuration | http_lib |
|
75
|
+
| c.hook_into :fakeweb | net/http |
|
76
|
+
| c.hook_into :webmock | net/http |
|
77
|
+
| c.hook_into :webmock | httpclient |
|
78
|
+
| c.hook_into :webmock | curb |
|
79
|
+
| c.hook_into :webmock | patron |
|
80
|
+
| c.hook_into :webmock | em-http-request |
|
81
|
+
| c.hook_into :webmock | typhoeus |
|
82
|
+
| c.hook_into :typhoeus | typhoeus |
|
83
|
+
| c.hook_into :excon | excon |
|
84
|
+
| | faraday (w/ net_http) |
|
85
|
+
| | faraday (w/ typhoeus) |
|
86
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Feature: Matching on Path
|
2
|
+
|
3
|
+
Use the `:path` request matcher to match requests on the path portion
|
4
|
+
of the request URI.
|
5
|
+
|
6
|
+
You can use this (alone, or in combination with `:host`) as an
|
7
|
+
alternative to `:uri` so that non-deterministic portions of the URI
|
8
|
+
are not considered as part of the request matching.
|
9
|
+
|
10
|
+
Background:
|
11
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
12
|
+
"""
|
13
|
+
---
|
14
|
+
- !ruby/struct:VCR::HTTPInteraction
|
15
|
+
request: !ruby/struct:VCR::Request
|
16
|
+
method: :post
|
17
|
+
uri: http://host1.com:80/about?date=2011-09-01
|
18
|
+
body:
|
19
|
+
headers:
|
20
|
+
response: !ruby/struct:VCR::Response
|
21
|
+
status: !ruby/struct:VCR::ResponseStatus
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
content-length:
|
26
|
+
- "14"
|
27
|
+
body: about response
|
28
|
+
http_version: "1.1"
|
29
|
+
- !ruby/struct:VCR::HTTPInteraction
|
30
|
+
request: !ruby/struct:VCR::Request
|
31
|
+
method: :post
|
32
|
+
uri: http://host2.com:80/home?date=2011-09-01
|
33
|
+
body:
|
34
|
+
headers:
|
35
|
+
response: !ruby/struct:VCR::Response
|
36
|
+
status: !ruby/struct:VCR::ResponseStatus
|
37
|
+
code: 200
|
38
|
+
message: OK
|
39
|
+
headers:
|
40
|
+
content-length:
|
41
|
+
- "15"
|
42
|
+
body: home response
|
43
|
+
http_version: "1.1"
|
44
|
+
"""
|
45
|
+
|
46
|
+
Scenario Outline: Replay interaction that matches the path
|
47
|
+
And a file named "path_matching.rb" with:
|
48
|
+
"""ruby
|
49
|
+
include_http_adapter_for("<http_lib>")
|
50
|
+
|
51
|
+
require 'vcr'
|
52
|
+
|
53
|
+
VCR.configure do |c|
|
54
|
+
<configuration>
|
55
|
+
c.cassette_library_dir = 'cassettes'
|
56
|
+
end
|
57
|
+
|
58
|
+
VCR.use_cassette('example', :match_requests_on => [:path]) do
|
59
|
+
puts "Response for /home: " + response_body_for(:get, "http://example.com/home")
|
60
|
+
end
|
61
|
+
|
62
|
+
VCR.use_cassette('example', :match_requests_on => [:path]) do
|
63
|
+
puts "Response for /about: " + response_body_for(:get, "http://example.com/about")
|
64
|
+
end
|
65
|
+
"""
|
66
|
+
When I run `ruby path_matching.rb`
|
67
|
+
Then it should pass with:
|
68
|
+
"""
|
69
|
+
Response for /home: home response
|
70
|
+
Response for /about: about response
|
71
|
+
"""
|
72
|
+
|
73
|
+
Examples:
|
74
|
+
| configuration | http_lib |
|
75
|
+
| c.hook_into :fakeweb | net/http |
|
76
|
+
| c.hook_into :webmock | net/http |
|
77
|
+
| c.hook_into :webmock | httpclient |
|
78
|
+
| c.hook_into :webmock | curb |
|
79
|
+
| c.hook_into :webmock | patron |
|
80
|
+
| c.hook_into :webmock | em-http-request |
|
81
|
+
| c.hook_into :webmock | typhoeus |
|
82
|
+
| c.hook_into :typhoeus | typhoeus |
|
83
|
+
| c.hook_into :excon | excon |
|
84
|
+
| | faraday (w/ net_http) |
|
85
|
+
| | faraday (w/ typhoeus) |
|
86
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
Feature: Playback repeats
|
2
|
+
|
3
|
+
By default, each response in a cassette can only be matched and played back
|
4
|
+
once while the cassette is in use (it can, of course, be re-used in multiple
|
5
|
+
tests, each of which should use the cassette separately). Note that this is
|
6
|
+
a change from the behavior in VCR 1.x. The old behavior occurred because of
|
7
|
+
how FakeWeb and WebMock behave internally and was not intended. Repeats create
|
8
|
+
less accurate tests since the real HTTP server may not necessarily return the
|
9
|
+
same response when identical requests are made in sequence.
|
10
|
+
|
11
|
+
If you want to allow playback repeats, VCR has a cassette option for this:
|
12
|
+
|
13
|
+
:allow_playback_repeats => true
|
14
|
+
|
15
|
+
Scenario: Responses do not repeat by default
|
16
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
17
|
+
"""
|
18
|
+
---
|
19
|
+
- !ruby/struct:VCR::HTTPInteraction
|
20
|
+
request: !ruby/struct:VCR::Request
|
21
|
+
method: :get
|
22
|
+
uri: http://example.com:80/foo
|
23
|
+
body:
|
24
|
+
headers:
|
25
|
+
response: !ruby/struct:VCR::Response
|
26
|
+
status: !ruby/struct:VCR::ResponseStatus
|
27
|
+
code: 200
|
28
|
+
message: OK
|
29
|
+
headers:
|
30
|
+
content-length:
|
31
|
+
- "10"
|
32
|
+
body: Response 1
|
33
|
+
http_version: "1.1"
|
34
|
+
- !ruby/struct:VCR::HTTPInteraction
|
35
|
+
request: !ruby/struct:VCR::Request
|
36
|
+
method: :get
|
37
|
+
uri: http://example.com:80/foo
|
38
|
+
body:
|
39
|
+
headers:
|
40
|
+
response: !ruby/struct:VCR::Response
|
41
|
+
status: !ruby/struct:VCR::ResponseStatus
|
42
|
+
code: 200
|
43
|
+
message: OK
|
44
|
+
headers:
|
45
|
+
content-length:
|
46
|
+
- "10"
|
47
|
+
body: Response 2
|
48
|
+
http_version: "1.1"
|
49
|
+
"""
|
50
|
+
And a file named "playback_repeats.rb" with:
|
51
|
+
"""ruby
|
52
|
+
include_http_adapter_for("net/http")
|
53
|
+
|
54
|
+
require 'vcr'
|
55
|
+
|
56
|
+
VCR.configure do |c|
|
57
|
+
c.hook_into :fakeweb
|
58
|
+
c.cassette_library_dir = 'cassettes'
|
59
|
+
end
|
60
|
+
|
61
|
+
puts "== With :allow_playback_repeats =="
|
62
|
+
VCR.use_cassette('example', :allow_playback_repeats => true) do
|
63
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
64
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
65
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "\n== Without :allow_playback_repeats =="
|
69
|
+
VCR.use_cassette('example') do
|
70
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
71
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
72
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
73
|
+
end
|
74
|
+
"""
|
75
|
+
When I run `ruby playback_repeats.rb`
|
76
|
+
Then it should fail with "Real HTTP connections are disabled"
|
77
|
+
And the output should contain:
|
78
|
+
"""
|
79
|
+
== With :allow_playback_repeats ==
|
80
|
+
Response 1
|
81
|
+
Response 2
|
82
|
+
Response 2
|
83
|
+
|
84
|
+
== Without :allow_playback_repeats ==
|
85
|
+
Response 1
|
86
|
+
Response 2
|
87
|
+
"""
|