vcr 3.0.3 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/lib/vcr/cassette/erb_renderer.rb +4 -2
  3. data/lib/vcr/cassette/http_interaction_list.rb +14 -9
  4. data/lib/vcr/cassette/migrator.rb +5 -6
  5. data/lib/vcr/cassette/persisters/file_system.rb +9 -1
  6. data/lib/vcr/cassette/serializers/compressed.rb +2 -2
  7. data/lib/vcr/cassette/serializers/json.rb +14 -8
  8. data/lib/vcr/cassette/serializers/psych.rb +10 -2
  9. data/lib/vcr/cassette/serializers/syck.rb +7 -1
  10. data/lib/vcr/cassette/serializers/yaml.rb +14 -2
  11. data/lib/vcr/cassette/serializers.rb +10 -0
  12. data/lib/vcr/cassette.rb +63 -16
  13. data/lib/vcr/configuration.rb +21 -8
  14. data/lib/vcr/deprecations.rb +0 -62
  15. data/lib/vcr/errors.rb +17 -12
  16. data/lib/vcr/library_hooks/excon.rb +8 -0
  17. data/lib/vcr/library_hooks/typhoeus.rb +91 -79
  18. data/lib/vcr/library_hooks/webmock.rb +2 -11
  19. data/lib/vcr/linked_cassette.rb +4 -4
  20. data/lib/vcr/middleware/excon.rb +1 -1
  21. data/lib/vcr/middleware/faraday.rb +29 -2
  22. data/lib/vcr/request_ignorer.rb +8 -1
  23. data/lib/vcr/request_matcher_registry.rb +3 -3
  24. data/lib/vcr/structs.rb +48 -32
  25. data/lib/vcr/test_frameworks/cucumber.rb +16 -5
  26. data/lib/vcr/test_frameworks/rspec.rb +34 -22
  27. data/lib/vcr/util/hooks.rb +1 -0
  28. data/lib/vcr/util/internet_connection.rb +15 -21
  29. data/lib/vcr/version.rb +2 -2
  30. data/lib/vcr.rb +52 -2
  31. metadata +45 -272
  32. data/features/CHANGELOG.md +0 -710
  33. data/features/CONTRIBUTING.md +0 -26
  34. data/features/LICENSE.md +0 -20
  35. data/features/README.md +0 -339
  36. data/features/Upgrade.md +0 -289
  37. data/features/about_these_examples.md +0 -18
  38. data/features/cassettes/allow_unused_http_interactions.feature +0 -100
  39. data/features/cassettes/automatic_re_recording.feature +0 -72
  40. data/features/cassettes/decompress.feature +0 -74
  41. data/features/cassettes/dynamic_erb.feature +0 -100
  42. data/features/cassettes/exclusive.feature +0 -126
  43. data/features/cassettes/format.feature +0 -411
  44. data/features/cassettes/freezing_time.feature +0 -68
  45. data/features/cassettes/naming.feature +0 -28
  46. data/features/cassettes/no_cassette.feature +0 -152
  47. data/features/cassettes/update_content_length_header.feature +0 -112
  48. data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
  49. data/features/configuration/cassette_library_dir.feature +0 -31
  50. data/features/configuration/debug_logging.feature +0 -58
  51. data/features/configuration/default_cassette_options.feature +0 -100
  52. data/features/configuration/filter_sensitive_data.feature +0 -153
  53. data/features/configuration/hook_into.feature +0 -172
  54. data/features/configuration/ignore_request.feature +0 -192
  55. data/features/configuration/preserve_exact_body_bytes.feature +0 -108
  56. data/features/configuration/query_parser.feature +0 -84
  57. data/features/configuration/uri_parser.feature +0 -93
  58. data/features/getting_started.md +0 -82
  59. data/features/hooks/after_http_request.feature +0 -58
  60. data/features/hooks/around_http_request.feature +0 -57
  61. data/features/hooks/before_http_request.feature +0 -63
  62. data/features/hooks/before_playback.feature +0 -184
  63. data/features/hooks/before_record.feature +0 -172
  64. data/features/http_libraries/em_http_request.feature +0 -250
  65. data/features/http_libraries/net_http.feature +0 -179
  66. data/features/middleware/faraday.feature +0 -56
  67. data/features/middleware/rack.feature +0 -92
  68. data/features/record_modes/all.feature +0 -82
  69. data/features/record_modes/new_episodes.feature +0 -79
  70. data/features/record_modes/none.feature +0 -72
  71. data/features/record_modes/once.feature +0 -95
  72. data/features/request_matching/README.md +0 -30
  73. data/features/request_matching/body.feature +0 -91
  74. data/features/request_matching/body_as_json.feature +0 -90
  75. data/features/request_matching/custom_matcher.feature +0 -135
  76. data/features/request_matching/headers.feature +0 -85
  77. data/features/request_matching/host.feature +0 -95
  78. data/features/request_matching/identical_request_sequence.feature +0 -89
  79. data/features/request_matching/method.feature +0 -96
  80. data/features/request_matching/path.feature +0 -96
  81. data/features/request_matching/playback_repeats.feature +0 -98
  82. data/features/request_matching/query.feature +0 -97
  83. data/features/request_matching/uri.feature +0 -94
  84. data/features/request_matching/uri_without_param.feature +0 -101
  85. data/features/step_definitions/cli_steps.rb +0 -199
  86. data/features/support/env.rb +0 -46
  87. data/features/support/http_lib_filters.rb +0 -46
  88. data/features/test_frameworks/cucumber.feature +0 -211
  89. data/features/test_frameworks/rspec_macro.feature +0 -81
  90. data/features/test_frameworks/rspec_metadata.feature +0 -150
  91. data/features/test_frameworks/test_unit.feature +0 -49
  92. data/lib/vcr/extensions/net_http_response.rb +0 -36
  93. data/lib/vcr/library_hooks/fakeweb.rb +0 -197
  94. data/lib/vcr/library_hooks/typhoeus_0.4.rb +0 -103
  95. data/spec/acceptance/concurrency_spec.rb +0 -51
  96. data/spec/acceptance/threading_spec.rb +0 -34
  97. data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
  98. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  99. data/spec/fixtures/cassette_spec/example.yml +0 -111
  100. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
  101. data/spec/fixtures/fake_example_responses.yml +0 -110
  102. data/spec/fixtures/match_requests_on.yml +0 -187
  103. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
  104. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
  105. data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
  106. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
  107. data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
  108. data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
  109. data/spec/lib/vcr/cassette_spec.rb +0 -618
  110. data/spec/lib/vcr/configuration_spec.rb +0 -326
  111. data/spec/lib/vcr/deprecations_spec.rb +0 -85
  112. data/spec/lib/vcr/errors_spec.rb +0 -178
  113. data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
  114. data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
  115. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
  116. data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
  117. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
  118. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
  119. data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
  120. data/spec/lib/vcr/library_hooks_spec.rb +0 -51
  121. data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
  122. data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
  123. data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
  124. data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
  125. data/spec/lib/vcr/structs_spec.rb +0 -732
  126. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
  127. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
  128. data/spec/lib/vcr/util/hooks_spec.rb +0 -158
  129. data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
  130. data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
  131. data/spec/lib/vcr/version_spec.rb +0 -27
  132. data/spec/lib/vcr_spec.rb +0 -354
  133. data/spec/monkey_patches.rb +0 -186
  134. data/spec/spec_helper.rb +0 -63
  135. data/spec/support/configuration_stubbing.rb +0 -8
  136. data/spec/support/cucumber_helpers.rb +0 -39
  137. data/spec/support/fixnum_extension.rb +0 -10
  138. data/spec/support/http_library_adapters.rb +0 -289
  139. data/spec/support/limited_uri.rb +0 -21
  140. data/spec/support/ruby_interpreter.rb +0 -7
  141. data/spec/support/shared_example_groups/excon.rb +0 -63
  142. data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
  143. data/spec/support/shared_example_groups/request_hooks.rb +0 -59
  144. data/spec/support/sinatra_app.rb +0 -86
  145. data/spec/support/vcr_localhost_server.rb +0 -76
  146. data/spec/support/vcr_stub_helpers.rb +0 -17
data/features/Upgrade.md DELETED
@@ -1,289 +0,0 @@
1
- See the [Changelog](changelog) for a complete list of changes from VCR
2
- 1.x to 2.0. This file simply lists the most pertinent ones to upgrading.
3
-
4
- ## Supported Rubies
5
-
6
- Ruby 1.8.6 and 1.9.1 are no longer supported.
7
-
8
- ## Configuration Changes
9
-
10
- In VCR 1.x, your configuration block would be something like this:
11
-
12
- ``` ruby
13
- VCR.config do |c|
14
- c.cassette_library_dir = 'cassettes'
15
- c.stub_with :fakeweb, :typhoeus
16
- end
17
- ```
18
-
19
- This will continue to work in VCR 2.0 but will generate deprecation
20
- warnings. Instead, you should change this to:
21
-
22
- ``` ruby
23
- VCR.configure do |c|
24
- c.cassette_library_dir = 'cassettes'
25
- c.hook_into :fakeweb, :typhoeus
26
- end
27
- ```
28
-
29
- ## New Cassette Format
30
-
31
- The cassette format has changed between VCR 1.x and VCR 2.0.
32
- VCR 1.x cassettes cannot be used with VCR 2.0.
33
-
34
- The easiest way to upgrade is to simply delete your cassettes and
35
- re-record all of them. VCR also provides a rake task that attempts
36
- to upgrade your 1.x cassettes to the new 2.0 format. To use it, add
37
- the following line to your Rakefile:
38
-
39
- ``` ruby
40
- load 'vcr/tasks/vcr.rake'
41
- ```
42
-
43
- Then run `rake vcr:migrate_cassettes DIR=path/to/your/cassettes/directory` to
44
- upgrade your cassettes. Note that this rake task may be unable to
45
- upgrade some cassettes that make extensive use of ERB. In addition, now
46
- that VCR 2.0 does less normalization then before, it may not be able to
47
- migrate the cassette perfectly. It's recommended that you delete and
48
- re-record your cassettes if you are able.
49
-
50
- ## Custom Request Matchers
51
-
52
- VCR 2.0 allows you to register custom request matchers:
53
-
54
- ``` ruby
55
- VCR.configure do |c|
56
- c.register_request_matcher :port do |request_1, request_2|
57
- URI(request_1.uri).port == URI(request_2.uri).port
58
- end
59
- end
60
- ```
61
-
62
- You can also pass any callable (an object that responds to #call, such as a lambda)
63
- to the `:match_requests_on` option:
64
-
65
- ``` ruby
66
- port_matcher = lambda do |request_1, request_2|
67
- URI(request_1.uri).port == URI(request_2.uri).port
68
- end
69
-
70
- VCR.use_cassette("example", :match_requests_on => [:host, port_matcher, :method]) do
71
- # make an HTTP request
72
- end
73
- ```
74
-
75
- In addition, a helper method is provided for generating a custom
76
- matcher that ignores one or more query parameters:
77
-
78
- ``` ruby
79
- uri_without_timestamp = VCR.request_matchers.uri_without_param(:timestamp)
80
- VCR.configure do |c|
81
- c.register_request_matcher(:uri_without_timestamp, &uri_without_timestamp)
82
- end
83
- ```
84
-
85
- ## Custom Serializers
86
-
87
- VCR 2.0 supports multiple serializers. `:yaml`, `:json`, `:psych` and
88
- `:syck` are supported out of the box, and it's easy to implement your
89
- own. Custom serializers must implement `#file_extension`, `#serialize`
90
- and `#deserialize`:
91
-
92
- ``` ruby
93
- VCR.use_cassette("example", :serialize_with => :json) do
94
- # make an HTTP request
95
- end
96
-
97
- marshal_serializer = Object.new
98
- marshal_serializer.instance_eval do
99
- def file_extension
100
- "marsh"
101
- end
102
-
103
- def serialize(hash)
104
- Marshal.dump(hash)
105
- end
106
-
107
- def deserialize(string)
108
- Marshal.load(string)
109
- end
110
- end
111
-
112
- VCR.configure do |c|
113
- c.cassette_serializers[:marshal] = marshal_serializer
114
- c.default_cassette_options = { :serialize_with => :marshal }
115
- end
116
- ```
117
-
118
- ## Request Hooks
119
-
120
- VCR 2.0 has new request hooks, allowing you to inject custom logic
121
- before an HTTP request, after an HTTP request, or around an HTTP
122
- request:
123
-
124
- ``` ruby
125
- VCR.configure do |c|
126
- c.before_http_request do |request|
127
- # do something with the request
128
- end
129
-
130
- c.after_http_request do |request, response|
131
- # do something with the request or response
132
- end
133
-
134
- # around_http_request only works on ruby 1.9
135
- c.around_http_request do |request|
136
- uri = URI(request.uri)
137
- if uri.host == 'api.geocoder.com'
138
- # extract an address like "1700 E Pine St, Seattle, WA"
139
- # from a query like "address=1700+E+Pine+St%2C+Seattle%2C+WA"
140
- address = CGI.unescape(uri.query.split('=').last)
141
- VCR.use_cassette("geocoding/#{address}", &request)
142
- else
143
- request.proceed
144
- end
145
- end
146
- end
147
- ```
148
-
149
- ## Ignore a Request Based on Anything
150
-
151
- You can now define what requests get ignored using a block. This
152
- gives you the flexibility to ignore a requets based on anything.
153
-
154
- ``` ruby
155
- VCR.configure do |c|
156
- c.ignore_request do |request|
157
- uri = URI(request.uri)
158
- uri.host == 'localhost' && uri.port == 7500
159
- end
160
- end
161
- ```
162
-
163
- ## Integration with RSpec 2 Metadata
164
-
165
- VCR can integrate directly with RSpec metadata:
166
-
167
- ``` ruby
168
- VCR.configure do |c|
169
- c.configure_rspec_metadata!
170
- end
171
-
172
- RSpec.configure do |c|
173
- # so we can use `:vcr` rather than `:vcr => true`;
174
- # in RSpec 3 this will no longer be necessary.
175
- c.treat_symbols_as_metadata_keys_with_true_values = true
176
- end
177
-
178
- # apply it to an example group
179
- describe MyAPIWrapper, :vcr do
180
- end
181
-
182
- describe MyAPIWrapper do
183
- # apply it to an individual example
184
- it "does something", :vcr do
185
- end
186
-
187
- # set some cassette options
188
- it "does something", :vcr => { :record => :new_episodes } do
189
- end
190
-
191
- # override the cassette name
192
- it "does something", :vcr => { :cassette_name => "something" } do
193
- end
194
- end
195
- ```
196
-
197
- ## Improved Faraday Integration
198
-
199
- VCR 1.x integrated with Faraday but required that you insert
200
- `VCR::Middleware::Faraday` into your middleware stack and configure
201
- `stub_with :faraday`. VCR 2 now takes care of inserting itself
202
- into the Faraday middleware stack if you configure `hook_into :faraday`.
203
-
204
- ## Improved Unhandled Error Messages
205
-
206
- When VCR is unsure how to handle a request, the error message now contains
207
- suggestions for how you can configure VCR or your test so it can handle
208
- the request.
209
-
210
- ## Debug Logger
211
-
212
- VCR 2.0 has a new configuration option that will turn on a logging mode
213
- so you can get more insight into what VCR is doing, for troubleshooting
214
- purposes:
215
-
216
- ``` ruby
217
- VCR.configure do |c|
218
- c.debug_logger = File.open('log/vcr.log')
219
- # or...
220
- c.debug_logger = $stderr
221
- end
222
- ```
223
-
224
- ## Playback Changes
225
-
226
- In VCR 1.x, a single HTTP interaction could be played back multiple
227
- times. This was mostly due to how VCR was implemented using FakeWeb
228
- and WebMock, and was not really by design. It's more in keeping with
229
- the philosophy of VCR to record the entire sequence of HTTP interactions
230
- (including the duplicate requests). In VCR 2, each recorded HTTP
231
- interaction can only be played back once unless you use the new
232
- `:allow_playback_repeats` option.
233
-
234
- In VCR 1.x, request matching was delegated to the HTTP stubbing library
235
- (typically FakeWeb or WebMock). They contain some normalization logic
236
- that can treat some URIs that are different strings as equivalent.
237
- For example, WebMock ignores the ordering of query parameters:
238
-
239
- ``` ruby
240
- > require 'webmock'
241
- => true
242
- > uri1 = "http://foo.com/bar?a=1&b=2"
243
- => "http://foo.com/bar?a=1&b=2"
244
- > uri2 = "http://foo.com/bar?b=2&a=1"
245
- => "http://foo.com/bar?b=2&a=1"
246
- > uri1 == uri2
247
- => false
248
- > WebMock::Util::URI.normalize_uri(uri1) == WebMock::Util::URI.normalize_uri(uri2)
249
- => true
250
- ```
251
-
252
- VCR 2, the `:uri` matcher simply [uses string
253
- equality](https://github.com/myronmarston/vcr/blob/v2.0.0/lib/vcr/request_matcher_registry.rb#L111).
254
- This means that there are some cases of non-deterministic URIs that VCR
255
- 1.x matched but VCR 2.0 will not match. If you need the `:uri` matcher
256
- to be tolerant of slight variations like these, you can easily override
257
- it:
258
-
259
- ``` ruby
260
- VCR.configure do |c|
261
- c.register_request_matcher(:uri) do |r1, r2|
262
- WebMock::Util::URI.normalize_uri(r1.uri) == WebMock::Util::URI.normalize_uri(r2.uri)
263
- end
264
- end
265
- ```
266
-
267
- ## Preserve Exact Body Bytes
268
-
269
- Sometimes the request or response body of an HTTP interaction cannot
270
- be serialized and deserialized properly. Usually this is due to the body
271
- having invalid UTF-8 bytes. This new option configures VCR to base64
272
- encode the body in order to preserve the bytes exactly. It can either
273
- be configured globally with a block, or set on individual cassettes:
274
-
275
- ``` ruby
276
- VCR.configure do |c|
277
- c.preserve_exact_body_bytes do |http_message|
278
- http_message.body.encoding.name == 'ASCII-8BIT' ||
279
- !http_message.body.valid_encoding?
280
- end
281
- end
282
-
283
- # or....
284
-
285
- VCR.use_cassette("my_cassette", :preserve_exact_body_bytes => true) do
286
- # ...
287
- end
288
- ```
289
-
@@ -1,18 +0,0 @@
1
- The cucumber features provided here demonstrate all of the major features of
2
- VCR. These features are executable documentation for VCR.
3
-
4
- Many of the examples use one (or both) of these helper functions
5
- provided by `spec/support/cucumber_helpers.rb`:
6
-
7
- * `start_sinatra_app`: starts a sinatra application on the given port.
8
- The server automatically shuts down when the ruby script ends. Many
9
- examples re-run the script without the sinatra server to demonstrate
10
- the replaying of a recorded HTTP response.
11
- * `include_http_adapter_for`: includes a module that implements a common
12
- HTTP interface for the given HTTP library. The `response_body_for`
13
- method will make an HTTP request using the given library. This
14
- allows scenarios to be run against each different supported HTTP
15
- library.
16
-
17
- If you have ideas to clarify or improve any of these cucumber features,
18
- please submit an [issue](https://github.com/vcr/vcr/issues) or pull request.
@@ -1,100 +0,0 @@
1
- Feature: Allow Unused HTTP Interactions
2
-
3
- If set to false, this cassette option will cause VCR to raise an error
4
- when a cassette is ejected and there are unused HTTP interactions remaining,
5
- unless there is already an exception unwinding the callstack.
6
-
7
- It verifies that all requests included in the cassette were made, and allows
8
- VCR to function a bit like a mock object at the HTTP layer.
9
-
10
- The option defaults to true (mostly for backwards compatibility).
11
-
12
- Background:
13
- Given a file named "vcr_config.rb" with:
14
- """ruby
15
- require 'vcr'
16
-
17
- VCR.configure do |c|
18
- c.hook_into :webmock
19
- c.cassette_library_dir = 'cassettes'
20
- end
21
- """
22
- And a previously recorded cassette file "cassettes/example.yml" with:
23
- """
24
- ---
25
- http_interactions:
26
- - request:
27
- method: get
28
- uri: http://example.com/foo
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
- - "5"
40
- body:
41
- encoding: UTF-8
42
- string: Hello
43
- http_version: "1.1"
44
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
45
- recorded_with: VCR 2.0.0
46
- """
47
-
48
- Scenario: Unused HTTP interactions are allowed by default
49
- Given a file named "allowed_by_default.rb" with:
50
- """ruby
51
- require 'vcr_config'
52
-
53
- VCR.use_cassette("example") do
54
- # no requests
55
- end
56
- """
57
- When I run `ruby allowed_by_default.rb`
58
- Then it should pass
59
-
60
- Scenario: Error raised if option is false and there are unused interactions
61
- Given a file named "disallowed_with_no_requests.rb" with:
62
- """ruby
63
- require 'vcr_config'
64
-
65
- VCR.use_cassette("example", :allow_unused_http_interactions => false) do
66
- # no requests
67
- end
68
- """
69
- When I run `ruby disallowed_with_no_requests.rb`
70
- Then it should fail with an error like:
71
- """
72
- There are unused HTTP interactions left in the cassette:
73
- - [get http://example.com/foo] => [200 "Hello"]
74
- """
75
-
76
- Scenario: No error raised if option is false and all interactions are used
77
- Given a file named "disallowed_with_all_requests.rb" with:
78
- """ruby
79
- require 'vcr_config'
80
-
81
- VCR.use_cassette("example", :allow_unused_http_interactions => false) do
82
- Net::HTTP.get_response(URI("http://example.com/foo"))
83
- end
84
- """
85
- When I run `ruby disallowed_with_all_requests.rb`
86
- Then it should pass
87
-
88
- Scenario: Does not silence other errors raised in `use_cassette` block
89
- Given a file named "does_not_silence_other_errors.rb" with:
90
- """ruby
91
- require 'vcr_config'
92
-
93
- VCR.use_cassette("example", :allow_unused_http_interactions => false) do
94
- raise "boom"
95
- end
96
- """
97
- When I run `ruby does_not_silence_other_errors.rb`
98
- Then it should fail with "boom"
99
- And the output should not contain "There are unused HTTP interactions"
100
-
@@ -1,72 +0,0 @@
1
- Feature: Automatic Re-recording
2
-
3
- Over time, your cassettes may get out-of-date. APIs change and sites you
4
- scrape get updated. VCR provides a facility to automatically re-record your
5
- cassettes. Enable re-recording using the `:re_record_interval` option.
6
-
7
- The value provided should be an interval (expressed in seconds) that
8
- determines how often VCR will re-record the cassette. When a cassette
9
- is used, VCR checks the earliest `recorded_at` timestamp in the cassette;
10
- if more time than the interval has passed since that timestamp,
11
- VCR will use the `:all` record mode to cause it be re-recorded.
12
-
13
- Background:
14
- Given a previously recorded cassette file "cassettes/example.yml" with:
15
- """
16
- ---
17
- http_interactions:
18
- - request:
19
- method: get
20
- uri: http://localhost/
21
- body:
22
- encoding: UTF-8
23
- string: ""
24
- headers: {}
25
- response:
26
- status:
27
- code: 200
28
- message: OK
29
- headers:
30
- Content-Length:
31
- - "12"
32
- body:
33
- encoding: UTF-8
34
- string: Old Response
35
- http_version: "1.1"
36
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
37
- recorded_with: VCR 2.0.0
38
- """
39
- And a file named "re_record.rb" with:
40
- """ruby
41
- $server = start_sinatra_app do
42
- get('/') { 'New Response' }
43
- end
44
-
45
- require 'vcr'
46
-
47
- VCR.configure do |c|
48
- c.hook_into :webmock
49
- c.cassette_library_dir = 'cassettes'
50
- end
51
-
52
- VCR.use_cassette('example', :re_record_interval => 7.days, :match_requests_on => [:method, :host, :path]) do
53
- puts Net::HTTP.get_response('localhost', '/', $server.port).body
54
- end
55
- """
56
-
57
- Scenario: Cassette is not re-recorded when not enough time has passed
58
- Given it is Tue, 07 Nov 2011
59
- When I run `ruby re_record.rb`
60
- Then the output should contain "Old Response"
61
- But the output should not contain "New Response"
62
- And the file "cassettes/example.yml" should contain "Old Response"
63
- But the file "cassettes/example.yml" should not contain "New Response"
64
-
65
- Scenario: Cassette is re-recorded when enough time has passed
66
- Given it is Tue, 09 Nov 2011
67
- When I run `ruby re_record.rb`
68
- Then the output should contain "New Response"
69
- But the output should not contain "Old Response"
70
- And the file "cassettes/example.yml" should contain "New Response"
71
- But the file "cassettes/example.yml" should not contain "Old Response"
72
-
@@ -1,74 +0,0 @@
1
- Feature: Decode compressed response
2
-
3
- When the `:decode_compressed_response` option is set to a truthy value, VCR
4
- will decompress "gzip" and "deflate" response bodies before recording. This
5
- ensures that these interactions become readable and editable after being
6
- serialized.
7
-
8
- This option should be avoided if the actual decompression of response bodies
9
- is part of the functionality of the library or app being tested.
10
-
11
- Background:
12
- Given a file named "decompress.rb" with:
13
- """ruby
14
- require 'zlib'
15
- require 'stringio'
16
-
17
- $server = start_sinatra_app do
18
- get('/') {
19
- content = 'The quick brown fox jumps over the lazy dog'
20
- io = StringIO.new
21
-
22
- writer = Zlib::GzipWriter.new(io)
23
- writer << content
24
- writer.close
25
-
26
- headers['Content-Encoding'] = 'gzip'
27
- io.string
28
- }
29
- end
30
-
31
- require 'vcr'
32
-
33
- VCR.configure do |c|
34
- c.cassette_library_dir = 'cassettes'
35
- c.hook_into :webmock
36
- c.default_cassette_options = { :serialize_with => :syck }
37
- end
38
- """
39
-
40
- Scenario: The option is not set by default
41
- When I append to file "decompress.rb":
42
- """ruby
43
- VCR.use_cassette(:decompress) do
44
- Net::HTTP.start('localhost', $server.port) do |http|
45
- http.get('/', 'accept-encoding' => 'identity')
46
- end
47
- end
48
- """
49
- And I run `ruby decompress.rb`
50
- Then the file "cassettes/decompress.yml" should contain a YAML fragment like:
51
- """
52
- Content-Encoding:
53
- - gzip
54
- """
55
-
56
- Scenario: The option is enabled
57
- When I append to file "decompress.rb":
58
- """ruby
59
- VCR.use_cassette(:decompress, :decode_compressed_response => true) do
60
- Net::HTTP.start('localhost', $server.port) do |http|
61
- http.get('/', 'accept-encoding' => 'identity')
62
- end
63
- end
64
- """
65
- And I run `ruby decompress.rb`
66
- Then the file "cassettes/decompress.yml" should contain a YAML fragment like:
67
- """
68
- Content-Length:
69
- - '43'
70
- """
71
- And the file "cassettes/decompress.yml" should contain:
72
- """
73
- string: The quick brown fox jumps over the lazy dog
74
- """
@@ -1,100 +0,0 @@
1
- Feature: Dynamic ERB cassettes
2
-
3
- By default, cassettes are static: the exact response that was received
4
- when the cassette was recorded will be replayed for all future requests.
5
- Usually, this is fine, but in some cases you need something more dynamic.
6
- You can use ERB for this.
7
-
8
- To enable ERB evaluation of a cassette, pass the `:erb => true` option
9
- to a cassette. If you want to pass variables to the cassette, you can
10
- pass the names and values of the variables in a hash (`:erb => { ... }`).
11
-
12
- Scenario: Enable dynamic ERB cassette evalutation using :erb => true
13
- Given a previously recorded cassette file "cassettes/dynamic.yml" with:
14
- """
15
- ---
16
- http_interactions:
17
- - request:
18
- method: get
19
- uri: http://example.com/foo?a=<%= 'b' * 3 %>
20
- body:
21
- encoding: UTF-8
22
- string: ''
23
- headers: {}
24
- response:
25
- status:
26
- code: 200
27
- message: OK
28
- headers:
29
- Content-Type:
30
- - text/html;charset=utf-8
31
- Content-Length:
32
- - '9'
33
- body:
34
- encoding: UTF-8
35
- string: Hello <%= 'bar'.next %>
36
- http_version: '1.1'
37
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
38
- recorded_with: VCR 2.0.0
39
- """
40
- And a file named "dynamic_erb_example.rb" with:
41
- """ruby
42
- require 'vcr'
43
-
44
- VCR.configure do |c|
45
- c.hook_into :webmock
46
- c.cassette_library_dir = 'cassettes'
47
- end
48
-
49
- VCR.use_cassette('dynamic', :erb => true) do
50
- response = Net::HTTP.get_response('example.com', '/foo?a=bbb')
51
- puts "Response: #{response.body}"
52
- end
53
- """
54
- When I run `ruby dynamic_erb_example.rb`
55
- Then it should pass with "Response: Hello bas"
56
-
57
- Scenario: Pass arguments to the ERB using :erb => { ... }
58
- Given a previously recorded cassette file "cassettes/dynamic.yml" with:
59
- """
60
- ---
61
- http_interactions:
62
- - request:
63
- method: get
64
- uri: http://example.com/foo?a=<%= arg1 %>
65
- body:
66
- encoding: UTF-8
67
- string: ''
68
- headers: {}
69
- response:
70
- status:
71
- code: 200
72
- message: OK
73
- headers:
74
- Content-Type:
75
- - text/html;charset=utf-8
76
- Content-Length:
77
- - '9'
78
- body:
79
- encoding: UTF-8
80
- string: Hello <%= arg2 %>
81
- http_version: '1.1'
82
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
83
- recorded_with: VCR 2.0.0
84
- """
85
- And a file named "dynamic_erb_example.rb" with:
86
- """ruby
87
- require 'vcr'
88
-
89
- VCR.configure do |c|
90
- c.hook_into :webmock
91
- c.cassette_library_dir = 'cassettes'
92
- end
93
-
94
- VCR.use_cassette('dynamic', :erb => { :arg1 => 7, :arg2 => 'baz' }) do
95
- response = Net::HTTP.get_response('example.com', '/foo?a=7')
96
- puts "Response: #{response.body}"
97
- end
98
- """
99
- When I run `ruby dynamic_erb_example.rb`
100
- Then it should pass with "Response: Hello baz"