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
@@ -1,383 +0,0 @@
|
|
1
|
-
Feature: Request matching
|
2
|
-
|
3
|
-
In order to properly replay previously recorded requests, VCR must match new
|
4
|
-
HTTP requests to a previously recorded one. By default, it matches on HTTP
|
5
|
-
method and URI, since that is usually deterministic and fully identifies the
|
6
|
-
resource and action for typical RESTful APIs.
|
7
|
-
|
8
|
-
You can customize how VCR matches requests using the `:match_requests_on` option.
|
9
|
-
Specify an array of attributes to match on. Supported attributes are:
|
10
|
-
|
11
|
-
- `:method` - The HTTP method (i.e. GET, POST, PUT or DELETE) of the request.
|
12
|
-
- `:uri` - The full URI of the request.
|
13
|
-
- `:host` - The host of the URI. You can use this (alone, or in combination
|
14
|
-
with `:path`) as an alternative to `:uri` to cause VCR to match using a regex
|
15
|
-
that matches the host.
|
16
|
-
- `:path` - The path of the URI. You can use this (alone, or in combination
|
17
|
-
with `:host`) as an alternative to `:uri` to cause VCR to match using a regex
|
18
|
-
that matches the path.
|
19
|
-
- `:body` - The body of the request. (Unsupported when you use FakeWeb.)
|
20
|
-
- `:headers` - The request headers. (Unsupported when you use FakeWeb.)
|
21
|
-
|
22
|
-
Alternately, you can manually edit a cassette and change a URI to the YAML
|
23
|
-
of a regular expression.
|
24
|
-
|
25
|
-
When a cassette contains multiple HTTP interactions containing identical
|
26
|
-
match attributes, the responses are sequenced: the first matching request
|
27
|
-
will get the first response, the second matching request will get the
|
28
|
-
second response, etc.
|
29
|
-
|
30
|
-
Scenario Outline: identical requests rotate through different matching responses
|
31
|
-
Given a previously recorded cassette file "cassettes/example.yml" with:
|
32
|
-
"""
|
33
|
-
---
|
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 1
|
48
|
-
http_version: "1.1"
|
49
|
-
- !ruby/struct:VCR::HTTPInteraction
|
50
|
-
request: !ruby/struct:VCR::Request
|
51
|
-
method: :get
|
52
|
-
uri: http://example.com:80/foo
|
53
|
-
body:
|
54
|
-
headers:
|
55
|
-
response: !ruby/struct:VCR::Response
|
56
|
-
status: !ruby/struct:VCR::ResponseStatus
|
57
|
-
code: 200
|
58
|
-
message: OK
|
59
|
-
headers:
|
60
|
-
content-length:
|
61
|
-
- "10"
|
62
|
-
body: Response 2
|
63
|
-
http_version: "1.1"
|
64
|
-
"""
|
65
|
-
And a file named "rotate_responses.rb" with:
|
66
|
-
"""
|
67
|
-
require 'vcr_cucumber_helpers'
|
68
|
-
include_http_adapter_for("<http_lib>")
|
69
|
-
|
70
|
-
require 'vcr'
|
71
|
-
|
72
|
-
VCR.config do |c|
|
73
|
-
c.stub_with <stub_with>
|
74
|
-
c.cassette_library_dir = 'cassettes'
|
75
|
-
end
|
76
|
-
|
77
|
-
VCR.use_cassette('example', :record => :none) do
|
78
|
-
puts response_body_for(:get, 'http://example.com/foo')
|
79
|
-
puts response_body_for(:get, 'http://example.com/foo')
|
80
|
-
end
|
81
|
-
"""
|
82
|
-
When I run `ruby rotate_responses.rb`
|
83
|
-
Then it should pass with:
|
84
|
-
"""
|
85
|
-
Response 1
|
86
|
-
Response 2
|
87
|
-
"""
|
88
|
-
|
89
|
-
Examples:
|
90
|
-
| stub_with | http_lib |
|
91
|
-
| :fakeweb | net/http |
|
92
|
-
| :webmock | net/http |
|
93
|
-
| :webmock | httpclient |
|
94
|
-
| :webmock | patron |
|
95
|
-
| :webmock | curb |
|
96
|
-
| :webmock | em-http-request |
|
97
|
-
| :typhoeus | typhoeus |
|
98
|
-
| :excon | excon |
|
99
|
-
|
100
|
-
Scenario Outline: match on host and path (to ignore query params)
|
101
|
-
Given a previously recorded cassette file "cassettes/example.yml" with:
|
102
|
-
"""
|
103
|
-
---
|
104
|
-
- !ruby/struct:VCR::HTTPInteraction
|
105
|
-
request: !ruby/struct:VCR::Request
|
106
|
-
method: :get
|
107
|
-
uri: http://bar.com:80/foo?date=2010-11-09
|
108
|
-
body:
|
109
|
-
headers:
|
110
|
-
response: !ruby/struct:VCR::Response
|
111
|
-
status: !ruby/struct:VCR::ResponseStatus
|
112
|
-
code: 200
|
113
|
-
message: OK
|
114
|
-
headers:
|
115
|
-
content-length:
|
116
|
-
- "16"
|
117
|
-
body: bar.com response
|
118
|
-
http_version: "1.1"
|
119
|
-
- !ruby/struct:VCR::HTTPInteraction
|
120
|
-
request: !ruby/struct:VCR::Request
|
121
|
-
method: :get
|
122
|
-
uri: http://foo.com:80/bar?date=2010-11-10
|
123
|
-
body:
|
124
|
-
headers:
|
125
|
-
response: !ruby/struct:VCR::Response
|
126
|
-
status: !ruby/struct:VCR::ResponseStatus
|
127
|
-
code: 200
|
128
|
-
message: OK
|
129
|
-
headers:
|
130
|
-
content-length:
|
131
|
-
- "16"
|
132
|
-
body: foo.com response
|
133
|
-
http_version: "1.1"
|
134
|
-
"""
|
135
|
-
And a file named "host_path_matching.rb" with:
|
136
|
-
"""
|
137
|
-
require 'vcr_cucumber_helpers'
|
138
|
-
include_http_adapter_for("<http_lib>")
|
139
|
-
|
140
|
-
require 'vcr'
|
141
|
-
|
142
|
-
VCR.config do |c|
|
143
|
-
c.stub_with <stub_with>
|
144
|
-
c.cassette_library_dir = 'cassettes'
|
145
|
-
end
|
146
|
-
|
147
|
-
VCR.use_cassette('example', :record => :none, :match_requests_on => [:host, :path]) do
|
148
|
-
puts response_body_for(:post, "http://foo.com/bar?date=#{Date.today.to_s}")
|
149
|
-
puts response_body_for(:put, "http://bar.com/foo?date=#{Date.today.to_s}")
|
150
|
-
end
|
151
|
-
"""
|
152
|
-
When I run `ruby host_path_matching.rb`
|
153
|
-
Then it should pass with:
|
154
|
-
"""
|
155
|
-
foo.com response
|
156
|
-
bar.com response
|
157
|
-
"""
|
158
|
-
|
159
|
-
Examples:
|
160
|
-
| stub_with | http_lib |
|
161
|
-
| :fakeweb | net/http |
|
162
|
-
| :webmock | net/http |
|
163
|
-
| :webmock | httpclient |
|
164
|
-
| :webmock | patron |
|
165
|
-
| :webmock | curb |
|
166
|
-
| :webmock | em-http-request |
|
167
|
-
| :typhoeus | typhoeus |
|
168
|
-
| :excon | excon |
|
169
|
-
|
170
|
-
Scenario Outline: match on request body
|
171
|
-
Given a previously recorded cassette file "cassettes/example.yml" with:
|
172
|
-
"""
|
173
|
-
---
|
174
|
-
- !ruby/struct:VCR::HTTPInteraction
|
175
|
-
request: !ruby/struct:VCR::Request
|
176
|
-
method: :post
|
177
|
-
uri: http://example.com:80/
|
178
|
-
body: a=1
|
179
|
-
headers:
|
180
|
-
content-type:
|
181
|
-
- application/x-www-form-urlencoded
|
182
|
-
response: !ruby/struct:VCR::Response
|
183
|
-
status: !ruby/struct:VCR::ResponseStatus
|
184
|
-
code: 200
|
185
|
-
message: OK
|
186
|
-
headers:
|
187
|
-
content-length:
|
188
|
-
- "12"
|
189
|
-
body: a=1 response
|
190
|
-
http_version: "1.1"
|
191
|
-
- !ruby/struct:VCR::HTTPInteraction
|
192
|
-
request: !ruby/struct:VCR::Request
|
193
|
-
method: :post
|
194
|
-
uri: http://example.com:80/
|
195
|
-
body: a=2
|
196
|
-
headers:
|
197
|
-
content-type:
|
198
|
-
- application/x-www-form-urlencoded
|
199
|
-
response: !ruby/struct:VCR::Response
|
200
|
-
status: !ruby/struct:VCR::ResponseStatus
|
201
|
-
code: 200
|
202
|
-
message: OK
|
203
|
-
headers:
|
204
|
-
content-length:
|
205
|
-
- "12"
|
206
|
-
body: a=2 response
|
207
|
-
http_version: "1.1"
|
208
|
-
"""
|
209
|
-
And a file named "body_matching.rb" with:
|
210
|
-
"""
|
211
|
-
require 'vcr_cucumber_helpers'
|
212
|
-
include_http_adapter_for("<http_lib>")
|
213
|
-
|
214
|
-
require 'vcr'
|
215
|
-
|
216
|
-
VCR.config do |c|
|
217
|
-
c.stub_with <stub_with>
|
218
|
-
c.cassette_library_dir = 'cassettes'
|
219
|
-
end
|
220
|
-
|
221
|
-
VCR.use_cassette('example', :record => :none, :match_requests_on => [:method, :uri, :body]) do
|
222
|
-
puts response_body_for(:post, "http://example.com/", 'a=2')
|
223
|
-
puts response_body_for(:post, "http://example.com/", 'a=1')
|
224
|
-
end
|
225
|
-
"""
|
226
|
-
When I run `ruby body_matching.rb`
|
227
|
-
Then it should pass with:
|
228
|
-
"""
|
229
|
-
a=2 response
|
230
|
-
a=1 response
|
231
|
-
"""
|
232
|
-
|
233
|
-
Examples:
|
234
|
-
| stub_with | http_lib |
|
235
|
-
| :webmock | net/http |
|
236
|
-
| :webmock | httpclient |
|
237
|
-
| :webmock | patron |
|
238
|
-
| :webmock | curb |
|
239
|
-
| :webmock | em-http-request |
|
240
|
-
| :typhoeus | typhoeus |
|
241
|
-
| :excon | excon |
|
242
|
-
|
243
|
-
Scenario Outline: match on request headers
|
244
|
-
Given a previously recorded cassette file "cassettes/example.yml" with:
|
245
|
-
"""
|
246
|
-
---
|
247
|
-
- !ruby/struct:VCR::HTTPInteraction
|
248
|
-
request: !ruby/struct:VCR::Request
|
249
|
-
method: :get
|
250
|
-
uri: http://example.com:80/dashboard
|
251
|
-
body:
|
252
|
-
headers:
|
253
|
-
x-user-id:
|
254
|
-
- "17"
|
255
|
-
response: !ruby/struct:VCR::Response
|
256
|
-
status: !ruby/struct:VCR::ResponseStatus
|
257
|
-
code: 200
|
258
|
-
message: OK
|
259
|
-
headers:
|
260
|
-
content-length:
|
261
|
-
- "16"
|
262
|
-
body: user 17 response
|
263
|
-
http_version: "1.1"
|
264
|
-
- !ruby/struct:VCR::HTTPInteraction
|
265
|
-
request: !ruby/struct:VCR::Request
|
266
|
-
method: :get
|
267
|
-
uri: http://example.com:80/dashboard
|
268
|
-
body:
|
269
|
-
headers:
|
270
|
-
x-user-id:
|
271
|
-
- "42"
|
272
|
-
response: !ruby/struct:VCR::Response
|
273
|
-
status: !ruby/struct:VCR::ResponseStatus
|
274
|
-
code: 200
|
275
|
-
message: OK
|
276
|
-
headers:
|
277
|
-
content-length:
|
278
|
-
- "16"
|
279
|
-
body: user 42 response
|
280
|
-
http_version: "1.1"
|
281
|
-
"""
|
282
|
-
And a file named "header_matching.rb" with:
|
283
|
-
"""
|
284
|
-
require 'vcr_cucumber_helpers'
|
285
|
-
include_http_adapter_for("<http_lib>")
|
286
|
-
|
287
|
-
require 'vcr'
|
288
|
-
|
289
|
-
VCR.config do |c|
|
290
|
-
c.stub_with <stub_with>
|
291
|
-
c.cassette_library_dir = 'cassettes'
|
292
|
-
end
|
293
|
-
|
294
|
-
VCR.use_cassette('example', :record => :none, :match_requests_on => [:method, :uri, :headers]) do
|
295
|
-
puts response_body_for(:get, "http://example.com/dashboard", nil, 'X-User-Id' => '42')
|
296
|
-
puts response_body_for(:get, "http://example.com/dashboard", nil, 'X-User-Id' => '17')
|
297
|
-
end
|
298
|
-
"""
|
299
|
-
When I run `ruby header_matching.rb`
|
300
|
-
Then it should pass with:
|
301
|
-
"""
|
302
|
-
user 42 response
|
303
|
-
user 17 response
|
304
|
-
"""
|
305
|
-
|
306
|
-
Examples:
|
307
|
-
| stub_with | http_lib |
|
308
|
-
| :webmock | net/http |
|
309
|
-
| :webmock | httpclient |
|
310
|
-
| :webmock | patron |
|
311
|
-
| :webmock | curb |
|
312
|
-
| :webmock | em-http-request |
|
313
|
-
| :typhoeus | typhoeus |
|
314
|
-
| :excon | excon |
|
315
|
-
|
316
|
-
Scenario Outline: Use a regex for the request URI
|
317
|
-
Given a previously recorded cassette file "cassettes/example.yml" with:
|
318
|
-
"""
|
319
|
-
---
|
320
|
-
- !ruby/struct:VCR::HTTPInteraction
|
321
|
-
request: !ruby/struct:VCR::Request
|
322
|
-
method: :get
|
323
|
-
uri: !ruby/regexp /^http:\/\/bar\.com\/foo/
|
324
|
-
body:
|
325
|
-
headers:
|
326
|
-
response: !ruby/struct:VCR::Response
|
327
|
-
status: !ruby/struct:VCR::ResponseStatus
|
328
|
-
code: 200
|
329
|
-
message: OK
|
330
|
-
headers:
|
331
|
-
content-length:
|
332
|
-
- "16"
|
333
|
-
body: bar.com response
|
334
|
-
http_version: "1.1"
|
335
|
-
- !ruby/struct:VCR::HTTPInteraction
|
336
|
-
request: !ruby/struct:VCR::Request
|
337
|
-
method: :get
|
338
|
-
uri: !ruby/regexp /^http:\/\/foo\.com\/bar/
|
339
|
-
body:
|
340
|
-
headers:
|
341
|
-
response: !ruby/struct:VCR::Response
|
342
|
-
status: !ruby/struct:VCR::ResponseStatus
|
343
|
-
code: 200
|
344
|
-
message: OK
|
345
|
-
headers:
|
346
|
-
content-length:
|
347
|
-
- "16"
|
348
|
-
body: foo.com response
|
349
|
-
http_version: "1.1"
|
350
|
-
"""
|
351
|
-
And a file named "uri_regex_matching.rb" with:
|
352
|
-
"""
|
353
|
-
require 'vcr_cucumber_helpers'
|
354
|
-
include_http_adapter_for("<http_lib>")
|
355
|
-
|
356
|
-
require 'vcr'
|
357
|
-
|
358
|
-
VCR.config do |c|
|
359
|
-
c.stub_with <stub_with>
|
360
|
-
c.cassette_library_dir = 'cassettes'
|
361
|
-
end
|
362
|
-
|
363
|
-
VCR.use_cassette('example', :record => :none) do
|
364
|
-
puts response_body_for(:get, "http://foo.com/bar?date=#{Date.today.to_s}")
|
365
|
-
puts response_body_for(:get, "http://bar.com/foo?date=#{Date.today.to_s}")
|
366
|
-
end
|
367
|
-
"""
|
368
|
-
When I run `ruby uri_regex_matching.rb`
|
369
|
-
Then it should pass with:
|
370
|
-
"""
|
371
|
-
foo.com response
|
372
|
-
bar.com response
|
373
|
-
"""
|
374
|
-
|
375
|
-
Examples:
|
376
|
-
| stub_with | http_lib |
|
377
|
-
| :fakeweb | net/http |
|
378
|
-
| :webmock | net/http |
|
379
|
-
| :webmock | httpclient |
|
380
|
-
| :webmock | patron |
|
381
|
-
| :webmock | curb |
|
382
|
-
| :webmock | em-http-request |
|
383
|
-
| :typhoeus | typhoeus |
|
data/lib/vcr/config.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'vcr/util/hooks'
|
3
|
-
|
4
|
-
module VCR
|
5
|
-
module Config
|
6
|
-
include VCR::Hooks
|
7
|
-
include VCR::VariableArgsBlockCaller
|
8
|
-
extend self
|
9
|
-
|
10
|
-
define_hook :before_record
|
11
|
-
define_hook :before_playback
|
12
|
-
|
13
|
-
attr_reader :cassette_library_dir
|
14
|
-
def cassette_library_dir=(cassette_library_dir)
|
15
|
-
@cassette_library_dir = cassette_library_dir
|
16
|
-
FileUtils.mkdir_p(cassette_library_dir) if cassette_library_dir
|
17
|
-
end
|
18
|
-
|
19
|
-
attr_writer :default_cassette_options
|
20
|
-
def default_cassette_options
|
21
|
-
@default_cassette_options ||= {}
|
22
|
-
@default_cassette_options[:match_requests_on] ||= RequestMatcher::DEFAULT_MATCH_ATTRIBUTES
|
23
|
-
@default_cassette_options[:record] ||= :once
|
24
|
-
@default_cassette_options
|
25
|
-
end
|
26
|
-
|
27
|
-
def stub_with(*http_stubbing_libraries)
|
28
|
-
@http_stubbing_libraries = http_stubbing_libraries
|
29
|
-
end
|
30
|
-
|
31
|
-
def http_stubbing_libraries
|
32
|
-
@http_stubbing_libraries ||= []
|
33
|
-
end
|
34
|
-
|
35
|
-
def ignore_hosts(*hosts)
|
36
|
-
ignored_hosts.push(*hosts).uniq!
|
37
|
-
VCR.http_stubbing_adapter.ignored_hosts = ignored_hosts if http_stubbing_libraries.any?
|
38
|
-
end
|
39
|
-
alias ignore_host ignore_hosts
|
40
|
-
|
41
|
-
def ignored_hosts
|
42
|
-
@ignored_hosts ||= []
|
43
|
-
end
|
44
|
-
|
45
|
-
def ignore_localhost=(value)
|
46
|
-
if value
|
47
|
-
ignore_hosts(*VCR::LOCALHOST_ALIASES)
|
48
|
-
else
|
49
|
-
ignored_hosts.reject! { |h| VCR::LOCALHOST_ALIASES.include?(h) }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def allow_http_connections_when_no_cassette=(value)
|
54
|
-
@allow_http_connections_when_no_cassette = value
|
55
|
-
VCR.http_stubbing_adapter.set_http_connections_allowed_to_default if http_stubbing_libraries.any?
|
56
|
-
end
|
57
|
-
|
58
|
-
def allow_http_connections_when_no_cassette?
|
59
|
-
!!@allow_http_connections_when_no_cassette
|
60
|
-
end
|
61
|
-
|
62
|
-
def filter_sensitive_data(placeholder, tag = nil, &block)
|
63
|
-
before_record(tag) do |interaction|
|
64
|
-
interaction.filter!(call_block(block, interaction), placeholder)
|
65
|
-
end
|
66
|
-
|
67
|
-
before_playback(tag) do |interaction|
|
68
|
-
interaction.filter!(placeholder, call_block(block, interaction))
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def uri_should_be_ignored?(uri)
|
73
|
-
uri = URI.parse(uri) unless uri.respond_to?(:host)
|
74
|
-
ignored_hosts.include?(uri.host)
|
75
|
-
end
|
76
|
-
|
77
|
-
def initialize_ivars
|
78
|
-
@allow_http_connections_when_no_cassette = nil
|
79
|
-
end
|
80
|
-
|
81
|
-
initialize_ivars # to avoid warnings
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|