vcr 3.0.3 → 6.1.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 +50 -15
  13. data/lib/vcr/configuration.rb +20 -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 +10 -1
  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
@@ -1,126 +0,0 @@
1
- Feature: exclusive cassette
2
-
3
- VCR allows cassettes to be nested. This is particularly useful in
4
- a context like cucumber, where you may be using a cassette for an
5
- entire scenario, and also using a cassette within a particular step
6
- definition.
7
-
8
- By default, both the inner and outer cassettes are active. On each
9
- request, VCR will look for a matching HTTP interaction in the inner
10
- cassette, and it will use the outer cassette as a fall back if none
11
- can be found.
12
-
13
- If you do not want the HTTP interactions of the outer cassette considered,
14
- you can pass the `:exclusive` option, so that the inner cassette is
15
- used exclusively.
16
-
17
- Background:
18
- Given a previously recorded cassette file "cassettes/outer.yml" with:
19
- """
20
- ---
21
- http_interactions:
22
- - request:
23
- method: get
24
- uri: http://localhost/outer
25
- body:
26
- encoding: UTF-8
27
- string: ""
28
- headers: {}
29
- response:
30
- status:
31
- code: 200
32
- message: OK
33
- headers:
34
- Content-Length:
35
- - "18"
36
- body:
37
- encoding: UTF-8
38
- string: Old outer response
39
- http_version: "1.1"
40
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
41
- recorded_with: VCR 2.0.0
42
- """
43
- And a previously recorded cassette file "cassettes/inner.yml" with:
44
- """
45
- ---
46
- http_interactions:
47
- - request:
48
- method: get
49
- uri: http://localhost/inner
50
- body:
51
- encoding: UTF-8
52
- string: ""
53
- headers: {}
54
- response:
55
- status:
56
- code: 200
57
- message: OK
58
- headers:
59
- Content-Length:
60
- - "18"
61
- body:
62
- encoding: UTF-8
63
- string: Old inner response
64
- http_version: "1.1"
65
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
66
- recorded_with: VCR 2.0.0
67
- """
68
- And a file named "setup.rb" with:
69
- """ruby
70
- include_http_adapter_for("net/http")
71
-
72
- $server = start_sinatra_app do
73
- get('/:path') { "New #{params[:path]} response" }
74
- end
75
-
76
- require 'vcr'
77
-
78
- VCR.configure do |c|
79
- c.hook_into :webmock
80
- c.cassette_library_dir = 'cassettes'
81
- c.default_cassette_options = {
82
- :record => :new_episodes,
83
- :match_requests_on => [:method, :host, :path]
84
- }
85
- end
86
- """
87
-
88
- Scenario: Cassettes are not exclusive by default
89
- Given a file named "not_exclusive.rb" with:
90
- """ruby
91
- require 'setup'
92
-
93
- VCR.use_cassette('outer') do
94
- VCR.use_cassette('inner') do
95
- puts response_body_for(:get, "http://localhost:#{$server.port}/outer")
96
- puts response_body_for(:get, "http://localhost:#{$server.port}/inner")
97
- end
98
- end
99
- """
100
- When I run `ruby not_exclusive.rb`
101
- Then it should pass with:
102
- """
103
- Old outer response
104
- Old inner response
105
- """
106
-
107
- Scenario: Use an exclusive cassette
108
- Given a file named "exclusive.rb" with:
109
- """ruby
110
- require 'setup'
111
-
112
- VCR.use_cassette('outer') do
113
- VCR.use_cassette('inner', :exclusive => true) do
114
- puts response_body_for(:get, "http://localhost:#{$server.port}/outer")
115
- puts response_body_for(:get, "http://localhost:#{$server.port}/inner")
116
- end
117
- end
118
- """
119
- When I run `ruby exclusive.rb`
120
- Then it should pass with:
121
- """
122
- New outer response
123
- Old inner response
124
- """
125
- And the file "cassettes/inner.yml" should contain "New outer response"
126
-
@@ -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
-
@@ -1,28 +0,0 @@
1
- Feature: Naming
2
-
3
- When inserting or using a cassette, the first argument is the cassette name.
4
- You can use any string for the name. If you use the default `:file_system`
5
- storage backend, VCR will sanitize the string before using it as a file name,
6
- so that it is a file-system friendly file name.
7
-
8
- Scenario: Name sanitizing
9
- Given a file named "name_sanitizing.rb" with:
10
- """ruby
11
- $server = start_sinatra_app do
12
- get('/') { "Hello" }
13
- end
14
-
15
- require 'vcr'
16
-
17
- VCR.configure do |c|
18
- c.cassette_library_dir = 'cassettes'
19
- c.hook_into :webmock
20
- end
21
-
22
- VCR.use_cassette('Fee, Fi Fo Fum') do
23
- Net::HTTP.get_response('localhost', '/', $server.port)
24
- end
25
- """
26
- And the directory "cassettes" does not exist
27
- When I run `ruby name_sanitizing.rb`
28
- Then the file "cassettes/Fee_Fi_Fo_Fum.yml" should contain "Hello"