mustwin-vcr 2.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/features/about_these_examples.md +18 -0
- data/features/cassettes/allow_unused_http_interactions.feature +100 -0
- data/features/cassettes/automatic_re_recording.feature +72 -0
- data/features/cassettes/decompress.feature +74 -0
- data/features/cassettes/dynamic_erb.feature +100 -0
- data/features/cassettes/exclusive.feature +126 -0
- data/features/cassettes/format.feature +323 -0
- data/features/cassettes/freezing_time.feature +68 -0
- data/features/cassettes/naming.feature +28 -0
- data/features/cassettes/no_cassette.feature +152 -0
- data/features/cassettes/update_content_length_header.feature +112 -0
- data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
- data/features/configuration/cassette_library_dir.feature +31 -0
- data/features/configuration/debug_logging.feature +59 -0
- data/features/configuration/default_cassette_options.feature +100 -0
- data/features/configuration/filter_sensitive_data.feature +153 -0
- data/features/configuration/hook_into.feature +172 -0
- data/features/configuration/ignore_request.feature +192 -0
- data/features/configuration/preserve_exact_body_bytes.feature +108 -0
- data/features/configuration/query_parser.feature +84 -0
- data/features/configuration/uri_parser.feature +89 -0
- data/features/getting_started.md +82 -0
- data/features/hooks/after_http_request.feature +58 -0
- data/features/hooks/around_http_request.feature +57 -0
- data/features/hooks/before_http_request.feature +63 -0
- data/features/hooks/before_playback.feature +184 -0
- data/features/hooks/before_record.feature +172 -0
- data/features/http_libraries/em_http_request.feature +250 -0
- data/features/http_libraries/net_http.feature +179 -0
- data/features/middleware/faraday.feature +56 -0
- data/features/middleware/rack.feature +92 -0
- data/features/record_modes/all.feature +82 -0
- data/features/record_modes/new_episodes.feature +79 -0
- data/features/record_modes/none.feature +72 -0
- data/features/record_modes/once.feature +95 -0
- data/features/request_matching/README.md +30 -0
- data/features/request_matching/body.feature +91 -0
- data/features/request_matching/body_as_json.feature +90 -0
- data/features/request_matching/custom_matcher.feature +135 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +95 -0
- data/features/request_matching/identical_request_sequence.feature +89 -0
- data/features/request_matching/method.feature +96 -0
- data/features/request_matching/path.feature +96 -0
- data/features/request_matching/playback_repeats.feature +98 -0
- data/features/request_matching/query.feature +97 -0
- data/features/request_matching/uri.feature +94 -0
- data/features/request_matching/uri_without_param.feature +101 -0
- data/features/step_definitions/cli_steps.rb +193 -0
- data/features/support/env.rb +44 -0
- data/features/support/http_lib_filters.rb +53 -0
- data/features/test_frameworks/cucumber.feature +211 -0
- data/features/test_frameworks/rspec_macro.feature +81 -0
- data/features/test_frameworks/rspec_metadata.feature +150 -0
- data/features/test_frameworks/test_unit.feature +49 -0
- data/lib/vcr.rb +347 -0
- data/lib/vcr/cassette.rb +291 -0
- data/lib/vcr/cassette/erb_renderer.rb +55 -0
- data/lib/vcr/cassette/http_interaction_list.rb +108 -0
- data/lib/vcr/cassette/migrator.rb +118 -0
- data/lib/vcr/cassette/persisters.rb +42 -0
- data/lib/vcr/cassette/persisters/file_system.rb +64 -0
- data/lib/vcr/cassette/serializers.rb +57 -0
- data/lib/vcr/cassette/serializers/json.rb +48 -0
- data/lib/vcr/cassette/serializers/psych.rb +48 -0
- data/lib/vcr/cassette/serializers/syck.rb +61 -0
- data/lib/vcr/cassette/serializers/yaml.rb +50 -0
- data/lib/vcr/configuration.rb +555 -0
- data/lib/vcr/deprecations.rb +109 -0
- data/lib/vcr/errors.rb +266 -0
- data/lib/vcr/extensions/net_http_response.rb +36 -0
- data/lib/vcr/library_hooks.rb +18 -0
- data/lib/vcr/library_hooks/excon.rb +27 -0
- data/lib/vcr/library_hooks/fakeweb.rb +196 -0
- data/lib/vcr/library_hooks/faraday.rb +51 -0
- data/lib/vcr/library_hooks/typhoeus.rb +120 -0
- data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
- data/lib/vcr/library_hooks/webmock.rb +164 -0
- data/lib/vcr/middleware/excon.rb +221 -0
- data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
- data/lib/vcr/middleware/faraday.rb +118 -0
- data/lib/vcr/middleware/rack.rb +79 -0
- data/lib/vcr/request_handler.rb +114 -0
- data/lib/vcr/request_ignorer.rb +43 -0
- data/lib/vcr/request_matcher_registry.rb +149 -0
- data/lib/vcr/structs.rb +578 -0
- data/lib/vcr/tasks/vcr.rake +9 -0
- data/lib/vcr/test_frameworks/cucumber.rb +64 -0
- data/lib/vcr/test_frameworks/rspec.rb +47 -0
- data/lib/vcr/util/hooks.rb +61 -0
- data/lib/vcr/util/internet_connection.rb +43 -0
- data/lib/vcr/util/logger.rb +59 -0
- data/lib/vcr/util/variable_args_block_caller.rb +13 -0
- data/lib/vcr/util/version_checker.rb +48 -0
- data/lib/vcr/version.rb +34 -0
- data/spec/acceptance/threading_spec.rb +34 -0
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +111 -0
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
- data/spec/fixtures/fake_example_responses.yml +110 -0
- data/spec/fixtures/match_requests_on.yml +187 -0
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
- data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
- data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
- data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
- data/spec/lib/vcr/cassette_spec.rb +618 -0
- data/spec/lib/vcr/configuration_spec.rb +326 -0
- data/spec/lib/vcr/deprecations_spec.rb +85 -0
- data/spec/lib/vcr/errors_spec.rb +162 -0
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
- data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
- data/spec/lib/vcr/library_hooks_spec.rb +51 -0
- data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
- data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
- data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
- data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
- data/spec/lib/vcr/structs_spec.rb +732 -0
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
- data/spec/lib/vcr/util/hooks_spec.rb +158 -0
- data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
- data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
- data/spec/lib/vcr/version_spec.rb +27 -0
- data/spec/lib/vcr_spec.rb +349 -0
- data/spec/monkey_patches.rb +182 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/configuration_stubbing.rb +8 -0
- data/spec/support/cucumber_helpers.rb +35 -0
- data/spec/support/fixnum_extension.rb +10 -0
- data/spec/support/http_library_adapters.rb +289 -0
- data/spec/support/limited_uri.rb +21 -0
- data/spec/support/ruby_interpreter.rb +7 -0
- data/spec/support/shared_example_groups/excon.rb +63 -0
- data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
- data/spec/support/shared_example_groups/request_hooks.rb +59 -0
- data/spec/support/sinatra_app.rb +86 -0
- data/spec/support/vcr_localhost_server.rb +76 -0
- data/spec/support/vcr_stub_helpers.rb +17 -0
- metadata +677 -0
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
http_interactions:
|
|
13
|
+
- request:
|
|
14
|
+
method: get
|
|
15
|
+
uri: http://example.com/foo
|
|
16
|
+
body:
|
|
17
|
+
encoding: UTF-8
|
|
18
|
+
string: ""
|
|
19
|
+
headers: {}
|
|
20
|
+
response:
|
|
21
|
+
status:
|
|
22
|
+
code: 200
|
|
23
|
+
message: OK
|
|
24
|
+
headers:
|
|
25
|
+
Content-Length:
|
|
26
|
+
- "10"
|
|
27
|
+
body:
|
|
28
|
+
encoding: UTF-8
|
|
29
|
+
string: Response 1
|
|
30
|
+
http_version: "1.1"
|
|
31
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
32
|
+
- request:
|
|
33
|
+
method: get
|
|
34
|
+
uri: http://example.com/foo
|
|
35
|
+
body:
|
|
36
|
+
encoding: UTF-8
|
|
37
|
+
string: ""
|
|
38
|
+
headers: {}
|
|
39
|
+
response:
|
|
40
|
+
status:
|
|
41
|
+
code: 200
|
|
42
|
+
message: OK
|
|
43
|
+
headers:
|
|
44
|
+
Content-Length:
|
|
45
|
+
- "10"
|
|
46
|
+
body:
|
|
47
|
+
encoding: UTF-8
|
|
48
|
+
string: Response 2
|
|
49
|
+
http_version: "1.1"
|
|
50
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
51
|
+
recorded_with: VCR 2.0.0
|
|
52
|
+
"""
|
|
53
|
+
And a file named "rotate_responses.rb" with:
|
|
54
|
+
"""ruby
|
|
55
|
+
include_http_adapter_for("<http_lib>")
|
|
56
|
+
|
|
57
|
+
require 'vcr'
|
|
58
|
+
|
|
59
|
+
VCR.configure do |c|
|
|
60
|
+
<configuration>
|
|
61
|
+
c.cassette_library_dir = 'cassettes'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
VCR.use_cassette('example') do
|
|
65
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
66
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
67
|
+
end
|
|
68
|
+
"""
|
|
69
|
+
When I run `ruby rotate_responses.rb`
|
|
70
|
+
Then it should pass with:
|
|
71
|
+
"""
|
|
72
|
+
Response 1
|
|
73
|
+
Response 2
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
Examples:
|
|
77
|
+
| configuration | http_lib |
|
|
78
|
+
| c.hook_into :fakeweb | net/http |
|
|
79
|
+
| c.hook_into :webmock | net/http |
|
|
80
|
+
| c.hook_into :webmock | httpclient |
|
|
81
|
+
| c.hook_into :webmock | curb |
|
|
82
|
+
| c.hook_into :webmock | patron |
|
|
83
|
+
| c.hook_into :webmock | em-http-request |
|
|
84
|
+
| c.hook_into :webmock | typhoeus |
|
|
85
|
+
| c.hook_into :typhoeus | typhoeus |
|
|
86
|
+
| c.hook_into :excon | excon |
|
|
87
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
|
88
|
+
| c.hook_into :faraday | faraday (w/ typhoeus) |
|
|
89
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
http_interactions:
|
|
15
|
+
- request:
|
|
16
|
+
method: post
|
|
17
|
+
uri: http://post-request.com/
|
|
18
|
+
body:
|
|
19
|
+
encoding: UTF-8
|
|
20
|
+
string: ""
|
|
21
|
+
headers: {}
|
|
22
|
+
response:
|
|
23
|
+
status:
|
|
24
|
+
code: 200
|
|
25
|
+
message: OK
|
|
26
|
+
headers:
|
|
27
|
+
Content-Length:
|
|
28
|
+
- "13"
|
|
29
|
+
body:
|
|
30
|
+
encoding: UTF-8
|
|
31
|
+
string: post response
|
|
32
|
+
http_version: "1.1"
|
|
33
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
34
|
+
- request:
|
|
35
|
+
method: get
|
|
36
|
+
uri: http://get-request.com/
|
|
37
|
+
body:
|
|
38
|
+
encoding: UTF-8
|
|
39
|
+
string: ""
|
|
40
|
+
headers: {}
|
|
41
|
+
response:
|
|
42
|
+
status:
|
|
43
|
+
code: 200
|
|
44
|
+
message: OK
|
|
45
|
+
headers:
|
|
46
|
+
Content-Length:
|
|
47
|
+
- "12"
|
|
48
|
+
body:
|
|
49
|
+
encoding: UTF-8
|
|
50
|
+
string: get response
|
|
51
|
+
http_version: "1.1"
|
|
52
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
53
|
+
recorded_with: VCR 2.0.0
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
Scenario Outline: Replay interaction that matches the HTTP method
|
|
57
|
+
And a file named "method_matching.rb" with:
|
|
58
|
+
"""ruby
|
|
59
|
+
include_http_adapter_for("<http_lib>")
|
|
60
|
+
|
|
61
|
+
require 'vcr'
|
|
62
|
+
|
|
63
|
+
VCR.configure do |c|
|
|
64
|
+
<configuration>
|
|
65
|
+
c.cassette_library_dir = 'cassettes'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
VCR.use_cassette('example', :match_requests_on => [:method]) do
|
|
69
|
+
puts "Response for GET: " + response_body_for(:get, "http://example.com/")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
VCR.use_cassette('example', :match_requests_on => [:method]) do
|
|
73
|
+
puts "Response for POST: " + response_body_for(:post, "http://example.com/")
|
|
74
|
+
end
|
|
75
|
+
"""
|
|
76
|
+
When I run `ruby method_matching.rb`
|
|
77
|
+
Then it should pass with:
|
|
78
|
+
"""
|
|
79
|
+
Response for GET: get response
|
|
80
|
+
Response for POST: post response
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
| configuration | http_lib |
|
|
85
|
+
| c.hook_into :fakeweb | net/http |
|
|
86
|
+
| c.hook_into :webmock | net/http |
|
|
87
|
+
| c.hook_into :webmock | httpclient |
|
|
88
|
+
| c.hook_into :webmock | curb |
|
|
89
|
+
| c.hook_into :webmock | patron |
|
|
90
|
+
| c.hook_into :webmock | em-http-request |
|
|
91
|
+
| c.hook_into :webmock | typhoeus |
|
|
92
|
+
| c.hook_into :typhoeus | typhoeus |
|
|
93
|
+
| c.hook_into :excon | excon |
|
|
94
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
|
95
|
+
| c.hook_into :faraday | faraday (w/ typhoeus) |
|
|
96
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
http_interactions:
|
|
15
|
+
- request:
|
|
16
|
+
method: post
|
|
17
|
+
uri: http://host1.com/about?date=2011-09-01
|
|
18
|
+
body:
|
|
19
|
+
encoding: UTF-8
|
|
20
|
+
string: ""
|
|
21
|
+
headers: {}
|
|
22
|
+
response:
|
|
23
|
+
status:
|
|
24
|
+
code: 200
|
|
25
|
+
message: OK
|
|
26
|
+
headers:
|
|
27
|
+
Content-Length:
|
|
28
|
+
- "14"
|
|
29
|
+
body:
|
|
30
|
+
encoding: UTF-8
|
|
31
|
+
string: about response
|
|
32
|
+
http_version: "1.1"
|
|
33
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
34
|
+
- request:
|
|
35
|
+
method: post
|
|
36
|
+
uri: http://host2.com/home?date=2011-09-01
|
|
37
|
+
body:
|
|
38
|
+
encoding: UTF-8
|
|
39
|
+
string: ""
|
|
40
|
+
headers: {}
|
|
41
|
+
response:
|
|
42
|
+
status:
|
|
43
|
+
code: 200
|
|
44
|
+
message: OK
|
|
45
|
+
headers:
|
|
46
|
+
Content-Length:
|
|
47
|
+
- "15"
|
|
48
|
+
body:
|
|
49
|
+
encoding: UTF-8
|
|
50
|
+
string: home response
|
|
51
|
+
http_version: "1.1"
|
|
52
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
53
|
+
recorded_with: VCR 2.0.0
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
Scenario Outline: Replay interaction that matches the path
|
|
57
|
+
And a file named "path_matching.rb" with:
|
|
58
|
+
"""ruby
|
|
59
|
+
include_http_adapter_for("<http_lib>")
|
|
60
|
+
|
|
61
|
+
require 'vcr'
|
|
62
|
+
|
|
63
|
+
VCR.configure do |c|
|
|
64
|
+
<configuration>
|
|
65
|
+
c.cassette_library_dir = 'cassettes'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
VCR.use_cassette('example', :match_requests_on => [:path]) do
|
|
69
|
+
puts "Response for /home: " + response_body_for(:get, "http://example.com/home")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
VCR.use_cassette('example', :match_requests_on => [:path]) do
|
|
73
|
+
puts "Response for /about: " + response_body_for(:get, "http://example.com/about")
|
|
74
|
+
end
|
|
75
|
+
"""
|
|
76
|
+
When I run `ruby path_matching.rb`
|
|
77
|
+
Then it should pass with:
|
|
78
|
+
"""
|
|
79
|
+
Response for /home: home response
|
|
80
|
+
Response for /about: about response
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
| configuration | http_lib |
|
|
85
|
+
| c.hook_into :fakeweb | net/http |
|
|
86
|
+
| c.hook_into :webmock | net/http |
|
|
87
|
+
| c.hook_into :webmock | httpclient |
|
|
88
|
+
| c.hook_into :webmock | curb |
|
|
89
|
+
| c.hook_into :webmock | patron |
|
|
90
|
+
| c.hook_into :webmock | em-http-request |
|
|
91
|
+
| c.hook_into :webmock | typhoeus |
|
|
92
|
+
| c.hook_into :typhoeus | typhoeus |
|
|
93
|
+
| c.hook_into :excon | excon |
|
|
94
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
|
95
|
+
| c.hook_into :faraday | faraday (w/ typhoeus) |
|
|
96
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
@exclude-jruby
|
|
16
|
+
Scenario: Responses do not repeat by default
|
|
17
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
|
18
|
+
"""
|
|
19
|
+
---
|
|
20
|
+
http_interactions:
|
|
21
|
+
- request:
|
|
22
|
+
method: get
|
|
23
|
+
uri: http://example.com/foo
|
|
24
|
+
body:
|
|
25
|
+
encoding: UTF-8
|
|
26
|
+
string: ""
|
|
27
|
+
headers: {}
|
|
28
|
+
response:
|
|
29
|
+
status:
|
|
30
|
+
code: 200
|
|
31
|
+
message: OK
|
|
32
|
+
headers:
|
|
33
|
+
Content-Length:
|
|
34
|
+
- "10"
|
|
35
|
+
body:
|
|
36
|
+
encoding: UTF-8
|
|
37
|
+
string: Response 1
|
|
38
|
+
http_version: "1.1"
|
|
39
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
40
|
+
- request:
|
|
41
|
+
method: get
|
|
42
|
+
uri: http://example.com/foo
|
|
43
|
+
body:
|
|
44
|
+
encoding: UTF-8
|
|
45
|
+
string: ""
|
|
46
|
+
headers: {}
|
|
47
|
+
response:
|
|
48
|
+
status:
|
|
49
|
+
code: 200
|
|
50
|
+
message: OK
|
|
51
|
+
headers:
|
|
52
|
+
Content-Length:
|
|
53
|
+
- "10"
|
|
54
|
+
body:
|
|
55
|
+
encoding: UTF-8
|
|
56
|
+
string: Response 2
|
|
57
|
+
http_version: "1.1"
|
|
58
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
59
|
+
recorded_with: VCR 2.0.0
|
|
60
|
+
"""
|
|
61
|
+
And a file named "playback_repeats.rb" with:
|
|
62
|
+
"""ruby
|
|
63
|
+
include_http_adapter_for("net/http")
|
|
64
|
+
|
|
65
|
+
require 'vcr'
|
|
66
|
+
|
|
67
|
+
VCR.configure do |c|
|
|
68
|
+
c.hook_into :webmock
|
|
69
|
+
c.cassette_library_dir = 'cassettes'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
puts "== With :allow_playback_repeats =="
|
|
73
|
+
VCR.use_cassette('example', :allow_playback_repeats => true) do
|
|
74
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
75
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
76
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
puts "\n== Without :allow_playback_repeats =="
|
|
80
|
+
VCR.use_cassette('example') do
|
|
81
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
82
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
83
|
+
puts response_body_for(:get, 'http://example.com/foo')
|
|
84
|
+
end
|
|
85
|
+
"""
|
|
86
|
+
When I run `ruby playback_repeats.rb`
|
|
87
|
+
Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
|
|
88
|
+
And the output should contain:
|
|
89
|
+
"""
|
|
90
|
+
== With :allow_playback_repeats ==
|
|
91
|
+
Response 1
|
|
92
|
+
Response 2
|
|
93
|
+
Response 2
|
|
94
|
+
|
|
95
|
+
== Without :allow_playback_repeats ==
|
|
96
|
+
Response 1
|
|
97
|
+
Response 2
|
|
98
|
+
"""
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Feature: Matching on Query string
|
|
2
|
+
|
|
3
|
+
Use the `:query` request matcher to match requests on the query string
|
|
4
|
+
portion of the request URI.
|
|
5
|
+
|
|
6
|
+
You can use this (alone, or in combination with others) 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
|
+
http_interactions:
|
|
15
|
+
- request:
|
|
16
|
+
method: post
|
|
17
|
+
uri: http://host1.com/query?date=2011-09-01
|
|
18
|
+
body:
|
|
19
|
+
encoding: UTF-8
|
|
20
|
+
string: ""
|
|
21
|
+
headers: {}
|
|
22
|
+
response:
|
|
23
|
+
status:
|
|
24
|
+
code: 200
|
|
25
|
+
message: OK
|
|
26
|
+
headers:
|
|
27
|
+
Content-Length:
|
|
28
|
+
- "19"
|
|
29
|
+
body:
|
|
30
|
+
encoding: UTF-8
|
|
31
|
+
string: 2011-09-01 response
|
|
32
|
+
http_version: "1.1"
|
|
33
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
34
|
+
- request:
|
|
35
|
+
method: post
|
|
36
|
+
uri: http://host1.com/query?date=2011-09-02
|
|
37
|
+
body:
|
|
38
|
+
encoding: UTF-8
|
|
39
|
+
string: ""
|
|
40
|
+
headers: {}
|
|
41
|
+
response:
|
|
42
|
+
status:
|
|
43
|
+
code: 200
|
|
44
|
+
message: OK
|
|
45
|
+
headers:
|
|
46
|
+
Content-Length:
|
|
47
|
+
- "19"
|
|
48
|
+
body:
|
|
49
|
+
encoding: UTF-8
|
|
50
|
+
string: 2011-09-02 response
|
|
51
|
+
http_version: "1.1"
|
|
52
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
|
53
|
+
recorded_with: VCR 2.0.0
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
Scenario Outline: Replay interaction that matches the query string
|
|
57
|
+
And a file named "query_matching.rb" with:
|
|
58
|
+
"""ruby
|
|
59
|
+
include_http_adapter_for("<http_lib>")
|
|
60
|
+
|
|
61
|
+
require 'vcr'
|
|
62
|
+
|
|
63
|
+
VCR.configure do |c|
|
|
64
|
+
<configuration>
|
|
65
|
+
c.default_cassette_options = { :match_requests_on => [:query] }
|
|
66
|
+
c.cassette_library_dir = 'cassettes'
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
VCR.use_cassette('example', :match_requests_on => [:query]) do
|
|
70
|
+
puts "Response for 2011-09-01 /query: " + response_body_for(:get, "http://example.com/query?date=2011-09-01")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
VCR.use_cassette('example', :match_requests_on => [:query]) do
|
|
74
|
+
puts "Response for 2011-09-02 /query: " + response_body_for(:get, "http://example.com/query?date=2011-09-02")
|
|
75
|
+
end
|
|
76
|
+
"""
|
|
77
|
+
When I run `ruby query_matching.rb`
|
|
78
|
+
Then it should pass with:
|
|
79
|
+
"""
|
|
80
|
+
Response for 2011-09-01 /query: 2011-09-01 response
|
|
81
|
+
Response for 2011-09-02 /query: 2011-09-02 response
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
Examples:
|
|
85
|
+
| configuration | http_lib |
|
|
86
|
+
| c.hook_into :fakeweb | net/http |
|
|
87
|
+
| c.hook_into :webmock | net/http |
|
|
88
|
+
| c.hook_into :webmock | httpclient |
|
|
89
|
+
| c.hook_into :webmock | curb |
|
|
90
|
+
| c.hook_into :webmock | patron |
|
|
91
|
+
| c.hook_into :webmock | em-http-request |
|
|
92
|
+
| c.hook_into :webmock | typhoeus |
|
|
93
|
+
| c.hook_into :typhoeus | typhoeus |
|
|
94
|
+
| c.hook_into :excon | excon |
|
|
95
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
|
96
|
+
| c.hook_into :faraday | faraday (w/ typhoeus) |
|
|
97
|
+
|