vcr 3.0.3 → 4.0.0
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 +4 -4
- data/lib/vcr.rb +18 -1
- data/lib/vcr/cassette.rb +11 -3
- data/lib/vcr/cassette/persisters/file_system.rb +1 -1
- data/lib/vcr/configuration.rb +3 -5
- data/lib/vcr/deprecations.rb +0 -62
- data/lib/vcr/errors.rb +16 -0
- data/lib/vcr/library_hooks/typhoeus.rb +37 -8
- data/lib/vcr/middleware/faraday.rb +5 -1
- data/lib/vcr/structs.rb +1 -1
- data/lib/vcr/util/hooks.rb +1 -0
- data/lib/vcr/version.rb +1 -1
- metadata +9 -249
- data/features/CHANGELOG.md +0 -710
- data/features/CONTRIBUTING.md +0 -26
- data/features/LICENSE.md +0 -20
- data/features/README.md +0 -339
- data/features/Upgrade.md +0 -289
- data/features/about_these_examples.md +0 -18
- data/features/cassettes/allow_unused_http_interactions.feature +0 -100
- data/features/cassettes/automatic_re_recording.feature +0 -72
- data/features/cassettes/decompress.feature +0 -74
- data/features/cassettes/dynamic_erb.feature +0 -100
- data/features/cassettes/exclusive.feature +0 -126
- data/features/cassettes/format.feature +0 -411
- data/features/cassettes/freezing_time.feature +0 -68
- data/features/cassettes/naming.feature +0 -28
- data/features/cassettes/no_cassette.feature +0 -152
- data/features/cassettes/update_content_length_header.feature +0 -112
- data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
- data/features/configuration/cassette_library_dir.feature +0 -31
- data/features/configuration/debug_logging.feature +0 -58
- data/features/configuration/default_cassette_options.feature +0 -100
- data/features/configuration/filter_sensitive_data.feature +0 -153
- data/features/configuration/hook_into.feature +0 -172
- data/features/configuration/ignore_request.feature +0 -192
- data/features/configuration/preserve_exact_body_bytes.feature +0 -108
- data/features/configuration/query_parser.feature +0 -84
- data/features/configuration/uri_parser.feature +0 -93
- data/features/getting_started.md +0 -82
- data/features/hooks/after_http_request.feature +0 -58
- data/features/hooks/around_http_request.feature +0 -57
- data/features/hooks/before_http_request.feature +0 -63
- data/features/hooks/before_playback.feature +0 -184
- data/features/hooks/before_record.feature +0 -172
- data/features/http_libraries/em_http_request.feature +0 -250
- data/features/http_libraries/net_http.feature +0 -179
- data/features/middleware/faraday.feature +0 -56
- data/features/middleware/rack.feature +0 -92
- data/features/record_modes/all.feature +0 -82
- data/features/record_modes/new_episodes.feature +0 -79
- data/features/record_modes/none.feature +0 -72
- data/features/record_modes/once.feature +0 -95
- data/features/request_matching/README.md +0 -30
- data/features/request_matching/body.feature +0 -91
- data/features/request_matching/body_as_json.feature +0 -90
- data/features/request_matching/custom_matcher.feature +0 -135
- data/features/request_matching/headers.feature +0 -85
- data/features/request_matching/host.feature +0 -95
- data/features/request_matching/identical_request_sequence.feature +0 -89
- data/features/request_matching/method.feature +0 -96
- data/features/request_matching/path.feature +0 -96
- data/features/request_matching/playback_repeats.feature +0 -98
- data/features/request_matching/query.feature +0 -97
- data/features/request_matching/uri.feature +0 -94
- data/features/request_matching/uri_without_param.feature +0 -101
- data/features/step_definitions/cli_steps.rb +0 -199
- data/features/support/env.rb +0 -46
- data/features/support/http_lib_filters.rb +0 -46
- data/features/test_frameworks/cucumber.feature +0 -211
- data/features/test_frameworks/rspec_macro.feature +0 -81
- data/features/test_frameworks/rspec_metadata.feature +0 -150
- data/features/test_frameworks/test_unit.feature +0 -49
- data/lib/vcr/extensions/net_http_response.rb +0 -36
- data/lib/vcr/library_hooks/fakeweb.rb +0 -197
- data/spec/acceptance/concurrency_spec.rb +0 -51
- data/spec/acceptance/threading_spec.rb +0 -34
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +0 -111
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
- data/spec/fixtures/fake_example_responses.yml +0 -110
- data/spec/fixtures/match_requests_on.yml +0 -187
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
- data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
- data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
- data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
- data/spec/lib/vcr/cassette_spec.rb +0 -618
- data/spec/lib/vcr/configuration_spec.rb +0 -326
- data/spec/lib/vcr/deprecations_spec.rb +0 -85
- data/spec/lib/vcr/errors_spec.rb +0 -178
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
- data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
- data/spec/lib/vcr/library_hooks_spec.rb +0 -51
- data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
- data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
- data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
- data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
- data/spec/lib/vcr/structs_spec.rb +0 -732
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
- data/spec/lib/vcr/util/hooks_spec.rb +0 -158
- data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
- data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
- data/spec/lib/vcr/version_spec.rb +0 -27
- data/spec/lib/vcr_spec.rb +0 -354
- data/spec/monkey_patches.rb +0 -186
- data/spec/spec_helper.rb +0 -63
- data/spec/support/configuration_stubbing.rb +0 -8
- data/spec/support/cucumber_helpers.rb +0 -39
- data/spec/support/fixnum_extension.rb +0 -10
- data/spec/support/http_library_adapters.rb +0 -289
- data/spec/support/limited_uri.rb +0 -21
- data/spec/support/ruby_interpreter.rb +0 -7
- data/spec/support/shared_example_groups/excon.rb +0 -63
- data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
- data/spec/support/shared_example_groups/request_hooks.rb +0 -59
- data/spec/support/sinatra_app.rb +0 -86
- data/spec/support/vcr_localhost_server.rb +0 -76
- data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,411 +0,0 @@
|
|
1
|
-
Feature: Cassette format
|
2
|
-
|
3
|
-
VCR Cassettes are files that contain all of the information
|
4
|
-
about the requests and corresponding responses in a
|
5
|
-
human-readable/editable format. A cassette contains an array
|
6
|
-
of HTTP interactions, each of which has the following:
|
7
|
-
|
8
|
-
- request
|
9
|
-
- method
|
10
|
-
- uri
|
11
|
-
- body
|
12
|
-
- encoding
|
13
|
-
- string
|
14
|
-
- headers
|
15
|
-
- response
|
16
|
-
- status
|
17
|
-
- code
|
18
|
-
- message
|
19
|
-
- headers
|
20
|
-
- body
|
21
|
-
- encoding
|
22
|
-
- string
|
23
|
-
- http version
|
24
|
-
|
25
|
-
By default, VCR uses YAML to serialize this data. You can configure
|
26
|
-
VCR to use a different serializer, either on a cassette-by-cassette
|
27
|
-
basis, or as a default for all cassettes if you use the `default_cassette_options`.
|
28
|
-
|
29
|
-
VCR supports the following serializers out of the box:
|
30
|
-
|
31
|
-
- `:yaml`--Uses ruby's standard library YAML. This may use psych or syck,
|
32
|
-
depending on your ruby installation.
|
33
|
-
- `:syck`--Uses syck (the ruby 1.8 YAML engine). This is useful when using
|
34
|
-
VCR on a project that must run in environments where psych is not available
|
35
|
-
(such as on ruby 1.8), to ensure that syck is always used.
|
36
|
-
- `:psych`--Uses psych (the new ruby 1.9 YAML engine). This is useful when
|
37
|
-
you want to ensure that psych is always used.
|
38
|
-
- `:json`--Uses [multi_json](https://github.com/intridea/multi_json)
|
39
|
-
to serialize the cassette data as JSON.
|
40
|
-
- `:compressed`--Wraps the default YAML serializer with Zlib, writing
|
41
|
-
compressed cassettes to disk.
|
42
|
-
|
43
|
-
You can also register a custom serializer using:
|
44
|
-
|
45
|
-
VCR.configure do |config|
|
46
|
-
config.cassette_serializers[:my_custom_serializer] = my_serializer
|
47
|
-
end
|
48
|
-
|
49
|
-
Your serializer must implement the following methods:
|
50
|
-
|
51
|
-
- `file_extension`
|
52
|
-
- `serialize(hash)`
|
53
|
-
- `deserialize(string)`
|
54
|
-
|
55
|
-
Scenario Outline: Request/Response data is saved to disk as YAML by default
|
56
|
-
Given a file named "cassette_yaml.rb" with:
|
57
|
-
"""ruby
|
58
|
-
include_http_adapter_for("<http_lib>")
|
59
|
-
|
60
|
-
if ARGV.any?
|
61
|
-
$server = start_sinatra_app do
|
62
|
-
get('/:path') { ARGV[0] + ' ' + params[:path] }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
require 'vcr'
|
67
|
-
|
68
|
-
VCR.configure do |c|
|
69
|
-
<configuration>
|
70
|
-
c.cassette_library_dir = 'cassettes'
|
71
|
-
c.before_record do |i|
|
72
|
-
i.request.uri.sub!(/:\d+/, ':7777')
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
VCR.use_cassette('example') do
|
77
|
-
make_http_request(:get, "http://localhost:#{$server.port}/foo", nil, 'Accept-Encoding' => 'identity')
|
78
|
-
make_http_request(:get, "http://localhost:#{$server.port}/bar", nil, 'Accept-Encoding' => 'identity')
|
79
|
-
end
|
80
|
-
"""
|
81
|
-
When I successfully run `ruby cassette_yaml.rb 'Hello'`
|
82
|
-
Then the file "cassettes/example.yml" should contain YAML like:
|
83
|
-
"""
|
84
|
-
---
|
85
|
-
http_interactions:
|
86
|
-
- request:
|
87
|
-
method: get
|
88
|
-
uri: http://localhost:7777/foo
|
89
|
-
body:
|
90
|
-
encoding: UTF-8
|
91
|
-
string: ""
|
92
|
-
headers:
|
93
|
-
Accept-Encoding:
|
94
|
-
- identity
|
95
|
-
response:
|
96
|
-
status:
|
97
|
-
code: 200
|
98
|
-
message: OK
|
99
|
-
headers:
|
100
|
-
Content-Type:
|
101
|
-
- text/html;charset=utf-8
|
102
|
-
Content-Length:
|
103
|
-
- "9"
|
104
|
-
body:
|
105
|
-
encoding: UTF-8
|
106
|
-
string: Hello foo
|
107
|
-
http_version: "1.1"
|
108
|
-
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
109
|
-
- request:
|
110
|
-
method: get
|
111
|
-
uri: http://localhost:7777/bar
|
112
|
-
body:
|
113
|
-
encoding: UTF-8
|
114
|
-
string: ""
|
115
|
-
headers:
|
116
|
-
Accept-Encoding:
|
117
|
-
- identity
|
118
|
-
response:
|
119
|
-
status:
|
120
|
-
code: 200
|
121
|
-
message: OK
|
122
|
-
headers:
|
123
|
-
Content-Type:
|
124
|
-
- text/html;charset=utf-8
|
125
|
-
Content-Length:
|
126
|
-
- "9"
|
127
|
-
body:
|
128
|
-
encoding: UTF-8
|
129
|
-
string: Hello bar
|
130
|
-
http_version: "1.1"
|
131
|
-
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
132
|
-
recorded_with: VCR 2.0.0
|
133
|
-
"""
|
134
|
-
|
135
|
-
Examples:
|
136
|
-
| configuration | http_lib |
|
137
|
-
| c.hook_into :fakeweb | net/http |
|
138
|
-
| c.hook_into :webmock | net/http |
|
139
|
-
| c.hook_into :webmock | httpclient |
|
140
|
-
| c.hook_into :webmock | patron |
|
141
|
-
| c.hook_into :webmock | curb |
|
142
|
-
| c.hook_into :webmock | em-http-request |
|
143
|
-
| c.hook_into :webmock | typhoeus |
|
144
|
-
| c.hook_into :typhoeus | typhoeus |
|
145
|
-
| c.hook_into :excon | excon |
|
146
|
-
| c.hook_into :faraday | faraday (w/ net_http) |
|
147
|
-
|
148
|
-
Scenario: Request/Response data can be saved as JSON
|
149
|
-
Given a file named "cassette_json.rb" with:
|
150
|
-
"""ruby
|
151
|
-
include_http_adapter_for("net/http")
|
152
|
-
|
153
|
-
$server = start_sinatra_app do
|
154
|
-
get('/:path') { ARGV[0] + ' ' + params[:path] }
|
155
|
-
end
|
156
|
-
|
157
|
-
require 'vcr'
|
158
|
-
|
159
|
-
VCR.configure do |c|
|
160
|
-
c.hook_into :webmock
|
161
|
-
c.cassette_library_dir = 'cassettes'
|
162
|
-
c.before_record do |i|
|
163
|
-
i.request.uri.sub!(/:\d+/, ':7777')
|
164
|
-
end
|
165
|
-
c.default_cassette_options = {
|
166
|
-
:match_requests_on => [:method, :host, :path]
|
167
|
-
}
|
168
|
-
end
|
169
|
-
|
170
|
-
VCR.use_cassette('example', :serialize_with => :json) do
|
171
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/foo", nil, 'Accept-Encoding' => 'identity')
|
172
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/bar", nil, 'Accept-Encoding' => 'identity')
|
173
|
-
end
|
174
|
-
"""
|
175
|
-
When I run `ruby cassette_json.rb 'Hello'`
|
176
|
-
Then the file "cassettes/example.json" should contain JSON like:
|
177
|
-
"""json
|
178
|
-
{
|
179
|
-
"http_interactions": [
|
180
|
-
{
|
181
|
-
"response": {
|
182
|
-
"body": {
|
183
|
-
"encoding": "UTF-8",
|
184
|
-
"string": "Hello foo"
|
185
|
-
},
|
186
|
-
"http_version": null,
|
187
|
-
"status": { "code": 200, "message": "OK" },
|
188
|
-
"headers": {
|
189
|
-
"Date": [ "Thu, 27 Oct 2011 06:16:31 GMT" ],
|
190
|
-
"Content-Type": [ "text/html;charset=utf-8" ],
|
191
|
-
"Content-Length": [ "9" ],
|
192
|
-
"Server": [ "WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)" ],
|
193
|
-
"Connection": [ "Keep-Alive" ]
|
194
|
-
}
|
195
|
-
},
|
196
|
-
"request": {
|
197
|
-
"uri": "http://localhost:7777/foo",
|
198
|
-
"body": {
|
199
|
-
"encoding": "UTF-8",
|
200
|
-
"string": ""
|
201
|
-
},
|
202
|
-
"method": "get",
|
203
|
-
"headers": {
|
204
|
-
"Accept-Encoding": [ "identity" ]
|
205
|
-
}
|
206
|
-
},
|
207
|
-
"recorded_at": "Tue, 01 Nov 2011 04:58:44 GMT"
|
208
|
-
},
|
209
|
-
{
|
210
|
-
"response": {
|
211
|
-
"body": {
|
212
|
-
"encoding": "UTF-8",
|
213
|
-
"string": "Hello bar"
|
214
|
-
},
|
215
|
-
"http_version": null,
|
216
|
-
"status": { "code": 200, "message": "OK" },
|
217
|
-
"headers": {
|
218
|
-
"Date": [ "Thu, 27 Oct 2011 06:16:31 GMT" ],
|
219
|
-
"Content-Type": [ "text/html;charset=utf-8" ],
|
220
|
-
"Content-Length": [ "9" ],
|
221
|
-
"Server": [ "WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)" ],
|
222
|
-
"Connection": [ "Keep-Alive" ]
|
223
|
-
}
|
224
|
-
},
|
225
|
-
"request": {
|
226
|
-
"uri": "http://localhost:7777/bar",
|
227
|
-
"body": {
|
228
|
-
"encoding": "UTF-8",
|
229
|
-
"string": ""
|
230
|
-
},
|
231
|
-
"method": "get",
|
232
|
-
"headers": {
|
233
|
-
"Accept-Encoding": [ "identity" ]
|
234
|
-
}
|
235
|
-
},
|
236
|
-
"recorded_at": "Tue, 01 Nov 2011 04:58:44 GMT"
|
237
|
-
}
|
238
|
-
],
|
239
|
-
"recorded_with": "VCR 2.0.0"
|
240
|
-
}
|
241
|
-
"""
|
242
|
-
When I run `ruby cassette_json.rb`
|
243
|
-
Then it should pass with:
|
244
|
-
"""
|
245
|
-
Hello foo
|
246
|
-
Hello bar
|
247
|
-
"""
|
248
|
-
|
249
|
-
Scenario: Request/Response data can be saved as compressed YAML
|
250
|
-
Given a file named "cassette_compressed.rb" with:
|
251
|
-
"""ruby
|
252
|
-
include_http_adapter_for("net/http")
|
253
|
-
|
254
|
-
$server = start_sinatra_app do
|
255
|
-
get('/:path') { ARGV[0] + ' ' + params[:path] }
|
256
|
-
end
|
257
|
-
|
258
|
-
require 'vcr'
|
259
|
-
|
260
|
-
VCR.configure do |c|
|
261
|
-
c.hook_into :webmock
|
262
|
-
c.cassette_library_dir = 'cassettes'
|
263
|
-
c.before_record do |i|
|
264
|
-
i.request.uri.sub!(/:\d+/, ':7777')
|
265
|
-
end
|
266
|
-
c.default_cassette_options = {
|
267
|
-
:match_requests_on => [:method, :host, :path]
|
268
|
-
}
|
269
|
-
end
|
270
|
-
|
271
|
-
VCR.use_cassette('example', :serialize_with => :compressed) do
|
272
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/foo", nil, 'Accept-Encoding' => 'identity')
|
273
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/bar", nil, 'Accept-Encoding' => 'identity')
|
274
|
-
end
|
275
|
-
|
276
|
-
"""
|
277
|
-
When I run `ruby cassette_compressed.rb 'Hello'`
|
278
|
-
Then the file "cassettes/example.gz" should contain compressed YAML like:
|
279
|
-
"""
|
280
|
-
---
|
281
|
-
http_interactions:
|
282
|
-
- request:
|
283
|
-
method: get
|
284
|
-
uri: http://localhost:7777/foo
|
285
|
-
body:
|
286
|
-
encoding: UTF-8
|
287
|
-
string: ""
|
288
|
-
headers:
|
289
|
-
Accept-Encoding:
|
290
|
-
- identity
|
291
|
-
response:
|
292
|
-
status:
|
293
|
-
code: 200
|
294
|
-
message: OK
|
295
|
-
headers:
|
296
|
-
Content-Type:
|
297
|
-
- text/html;charset=utf-8
|
298
|
-
Content-Length:
|
299
|
-
- "9"
|
300
|
-
body:
|
301
|
-
encoding: UTF-8
|
302
|
-
string: Hello foo
|
303
|
-
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
304
|
-
- request:
|
305
|
-
method: get
|
306
|
-
uri: http://localhost:7777/bar
|
307
|
-
body:
|
308
|
-
encoding: UTF-8
|
309
|
-
string: ""
|
310
|
-
headers:
|
311
|
-
Accept-Encoding:
|
312
|
-
- identity
|
313
|
-
response:
|
314
|
-
status:
|
315
|
-
code: 200
|
316
|
-
message: OK
|
317
|
-
headers:
|
318
|
-
Content-Type:
|
319
|
-
- text/html;charset=utf-8
|
320
|
-
Content-Length:
|
321
|
-
- "9"
|
322
|
-
body:
|
323
|
-
encoding: UTF-8
|
324
|
-
string: Hello bar
|
325
|
-
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
326
|
-
recorded_with: VCR 2.0.0
|
327
|
-
"""
|
328
|
-
When I run `ruby cassette_compressed.rb`
|
329
|
-
Then it should pass with:
|
330
|
-
"""
|
331
|
-
Hello foo
|
332
|
-
Hello bar
|
333
|
-
"""
|
334
|
-
|
335
|
-
Scenario: Request/Response data can be saved using a custom serializer
|
336
|
-
Given a file named "cassette_ruby.rb" with:
|
337
|
-
"""ruby
|
338
|
-
include_http_adapter_for("net/http")
|
339
|
-
|
340
|
-
$server = start_sinatra_app do
|
341
|
-
get('/:path') { ARGV[0] + ' ' + params[:path] }
|
342
|
-
end
|
343
|
-
|
344
|
-
require 'vcr'
|
345
|
-
|
346
|
-
# purely for demonstration purposes; obviously, don't actually
|
347
|
-
# use ruby #inspect / #eval for your serialization...
|
348
|
-
ruby_serializer = Object.new
|
349
|
-
class << ruby_serializer
|
350
|
-
def file_extension; "ruby"; end
|
351
|
-
def serialize(hash); hash.inspect; end
|
352
|
-
def deserialize(string); eval(string); end
|
353
|
-
end
|
354
|
-
|
355
|
-
VCR.configure do |c|
|
356
|
-
c.hook_into :webmock
|
357
|
-
c.cassette_library_dir = 'cassettes'
|
358
|
-
c.cassette_serializers[:ruby] = ruby_serializer
|
359
|
-
c.before_record do |i|
|
360
|
-
i.request.uri.sub!(/:\d+/, ':7777')
|
361
|
-
end
|
362
|
-
c.default_cassette_options = {
|
363
|
-
:match_requests_on => [:method, :host, :path]
|
364
|
-
}
|
365
|
-
end
|
366
|
-
|
367
|
-
VCR.use_cassette('example', :serialize_with => :ruby) do
|
368
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/foo", nil, 'Accept-Encoding' => 'identity')
|
369
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/bar", nil, 'Accept-Encoding' => 'identity')
|
370
|
-
end
|
371
|
-
"""
|
372
|
-
When I run `ruby cassette_ruby.rb 'Hello'`
|
373
|
-
Then the file "cassettes/example.ruby" should contain ruby like:
|
374
|
-
"""
|
375
|
-
{"http_interactions"=>
|
376
|
-
[{"request"=>
|
377
|
-
{"method"=>"get",
|
378
|
-
"uri"=>"http://localhost:7777/foo",
|
379
|
-
"body"=>{"encoding"=>"UTF-8", "string"=>""},
|
380
|
-
"headers"=>{"Accept"=>["*/*"], "Accept-Encoding"=>["identity"], "User-Agent"=>["Ruby"]}},
|
381
|
-
"response"=>
|
382
|
-
{"status"=>{"code"=>200, "message"=>"OK "},
|
383
|
-
"headers"=>
|
384
|
-
{"Content-Type"=>["text/html;charset=utf-8"],
|
385
|
-
"Content-Length"=>["9"],
|
386
|
-
"Connection"=>["Keep-Alive"]},
|
387
|
-
"body"=>{"encoding"=>"UTF-8", "string"=>"Hello foo"},
|
388
|
-
"http_version"=>nil},
|
389
|
-
"recorded_at"=>"Tue, 01 Nov 2011 04:58:44 GMT"},
|
390
|
-
{"request"=>
|
391
|
-
{"method"=>"get",
|
392
|
-
"uri"=>"http://localhost:7777/bar",
|
393
|
-
"body"=>{"encoding"=>"UTF-8", "string"=>""},
|
394
|
-
"headers"=>{"Accept"=>["*/*"], "Accept-Encoding"=>["identity"], "User-Agent"=>["Ruby"]}},
|
395
|
-
"response"=>
|
396
|
-
{"status"=>{"code"=>200, "message"=>"OK "},
|
397
|
-
"headers"=>
|
398
|
-
{"Content-Type"=>["text/html;charset=utf-8"],
|
399
|
-
"Content-Length"=>["9"],
|
400
|
-
"Connection"=>["Keep-Alive"]},
|
401
|
-
"body"=>{"encoding"=>"UTF-8", "string"=>"Hello bar"},
|
402
|
-
"http_version"=>nil},
|
403
|
-
"recorded_at"=>"Tue, 01 Nov 2011 04:58:44 GMT"}],
|
404
|
-
"recorded_with"=>"VCR 2.0.0"}
|
405
|
-
"""
|
406
|
-
When I run `ruby cassette_ruby.rb`
|
407
|
-
Then it should pass with:
|
408
|
-
"""
|
409
|
-
Hello foo
|
410
|
-
Hello bar
|
411
|
-
"""
|
@@ -1,68 +0,0 @@
|
|
1
|
-
Feature: Freezing Time
|
2
|
-
|
3
|
-
When dealing with an HTTP API that includes time-based compontents
|
4
|
-
in the request (e.g. for signed S3 requests), it can be useful
|
5
|
-
on playback to freeze time to what it originally was when the
|
6
|
-
cassette was recorded so that the request is always the same
|
7
|
-
each time your test is run.
|
8
|
-
|
9
|
-
While VCR doesn't directly support time freezing, it does
|
10
|
-
expose `VCR::Cassette#originally_recorded_at`, which you can
|
11
|
-
easily use with a library like
|
12
|
-
[timecop](https://github.com/travisjeffery/timecop)
|
13
|
-
to freeze time.
|
14
|
-
|
15
|
-
Note: `VCR::Cassette#originally_recorded_at` will return `nil`
|
16
|
-
when the cassette is recording for the first time, so you'll
|
17
|
-
probably want to use an expression like
|
18
|
-
`cassette.originally_recorded_at || Time.now` so that it
|
19
|
-
will work when recording or when playing back.
|
20
|
-
|
21
|
-
Scenario: Previously recorded responses are replayed
|
22
|
-
Given a previously recorded cassette file "cassettes/example.yml" with:
|
23
|
-
"""
|
24
|
-
---
|
25
|
-
http_interactions:
|
26
|
-
- request:
|
27
|
-
method: get
|
28
|
-
uri: http://example.com/events/since/2013-09-23T17:00:30Z
|
29
|
-
body:
|
30
|
-
encoding: UTF-8
|
31
|
-
string: ""
|
32
|
-
headers: {}
|
33
|
-
response:
|
34
|
-
status:
|
35
|
-
code: 200
|
36
|
-
message: OK
|
37
|
-
headers:
|
38
|
-
Content-Length:
|
39
|
-
- "20"
|
40
|
-
body:
|
41
|
-
encoding: UTF-8
|
42
|
-
string: Some Event
|
43
|
-
http_version: "1.1"
|
44
|
-
recorded_at: Mon, 23 Sep 2013 17:00:30 GMT
|
45
|
-
recorded_with: VCR 2.0.0
|
46
|
-
"""
|
47
|
-
Given a file named "freeze_time.rb" with:
|
48
|
-
"""ruby
|
49
|
-
require 'time'
|
50
|
-
require 'timecop'
|
51
|
-
require 'vcr'
|
52
|
-
|
53
|
-
VCR.configure do |vcr|
|
54
|
-
vcr.cassette_library_dir = 'cassettes'
|
55
|
-
vcr.hook_into :webmock
|
56
|
-
end
|
57
|
-
|
58
|
-
VCR.use_cassette('example') do |cassette|
|
59
|
-
Timecop.freeze(cassette.originally_recorded_at || Time.now) do
|
60
|
-
path = "/events/since/#{Time.now.getutc.iso8601}"
|
61
|
-
response = Net::HTTP.get_response('example.com', path)
|
62
|
-
puts "Response: #{response.body}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
"""
|
66
|
-
When I run `ruby freeze_time.rb`
|
67
|
-
Then it should pass with "Response: Some Event"
|
68
|
-
|