vcr 1.3.1 → 1.3.2

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.
Files changed (72) hide show
  1. data/CHANGELOG.md +14 -2
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +20 -2
  4. data/README.md +6 -1
  5. data/Rakefile +6 -44
  6. data/benchmarks/http_stubbing_libraries.rb +4 -4
  7. data/cucumber.yml +14 -0
  8. data/features/README.md +21 -0
  9. data/features/cassettes/automatic_re_recording.feature +68 -0
  10. data/features/cassettes/dynamic_erb.feature +90 -0
  11. data/features/cassettes/format.feature +81 -0
  12. data/features/cassettes/no_cassette.feature +38 -0
  13. data/features/cassettes/record_modes/all.feature +78 -0
  14. data/features/cassettes/record_modes/new_episodes.feature +71 -0
  15. data/features/cassettes/record_modes/none.feature +65 -0
  16. data/features/cassettes/request_matching.feature +379 -0
  17. data/features/configuration/cassette_library_dir.feature +28 -0
  18. data/features/configuration/default_cassette_options.feature +80 -0
  19. data/features/configuration/ignore_localhost.feature +103 -0
  20. data/features/configuration/stub_with.feature +164 -0
  21. data/features/http_libraries/net_http.feature +137 -0
  22. data/features/step_definitions/cli_steps.rb +82 -0
  23. data/features/support/aruba_workaround/aruba_patches.rb +36 -0
  24. data/features/support/aruba_workaround/background_process.rb +4 -0
  25. data/features/support/env.rb +16 -102
  26. data/features/support/http_lib_filters.rb +37 -0
  27. data/features/support/vcr_cucumber_helpers.rb +34 -0
  28. data/features/test_frameworks/cucumber.feature +109 -0
  29. data/features/test_frameworks/rspec.feature +110 -0
  30. data/features/test_frameworks/shoulda.feature +64 -0
  31. data/features/test_frameworks/test_unit.feature +46 -0
  32. data/lib/vcr/cassette.rb +1 -1
  33. data/lib/vcr/structs.rb +64 -13
  34. data/lib/vcr/version.rb +1 -1
  35. data/{FullBuildRakeFile → script/FullBuildRakeFile} +0 -0
  36. data/script/full_build +1 -0
  37. data/spec/extensions/net_http_spec.rb +1 -1
  38. data/spec/spec_helper.rb +1 -1
  39. data/spec/structs_spec.rb +47 -16
  40. data/spec/support/vcr_localhost_server.rb +11 -5
  41. data/vcr.gemspec +2 -1
  42. metadata +82 -77
  43. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/regex_cassette.yml +0 -43
  44. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette1.yml +0 -43
  45. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette2.yml +0 -63
  46. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette3.yml +0 -85
  47. data/features/fixtures/vcr_cassettes/1.9.1/erb_cassette.yml +0 -36
  48. data/features/fixtures/vcr_cassettes/1.9.1/match_requests_on.yml +0 -35
  49. data/features/fixtures/vcr_cassettes/1.9.1/nested_replay_cassette.yml +0 -32
  50. data/features/fixtures/vcr_cassettes/1.9.1/not_the_real_response.yml +0 -43
  51. data/features/fixtures/vcr_cassettes/1.9.1/record_all.yml +0 -62
  52. data/features/fixtures/vcr_cassettes/1.9.1/replay_localhost_cassette.yml +0 -32
  53. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/regex_cassette.yml +0 -43
  54. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette1.yml +0 -43
  55. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette2.yml +0 -47
  56. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette3.yml +0 -85
  57. data/features/fixtures/vcr_cassettes/not_1.9.1/erb_cassette.yml +0 -36
  58. data/features/fixtures/vcr_cassettes/not_1.9.1/match_requests_on.yml +0 -35
  59. data/features/fixtures/vcr_cassettes/not_1.9.1/nested_replay_cassette.yml +0 -24
  60. data/features/fixtures/vcr_cassettes/not_1.9.1/not_the_real_response.yml +0 -43
  61. data/features/fixtures/vcr_cassettes/not_1.9.1/record_all.yml +0 -61
  62. data/features/fixtures/vcr_cassettes/not_1.9.1/replay_localhost_cassette.yml +0 -32
  63. data/features/http_client.feature +0 -16
  64. data/features/net_http.feature +0 -38
  65. data/features/record_response.feature +0 -95
  66. data/features/replay_recorded_response.feature +0 -96
  67. data/features/rspec.feature +0 -100
  68. data/features/step_definitions/http_client_steps.rb +0 -7
  69. data/features/step_definitions/net_http_steps.rb +0 -49
  70. data/features/step_definitions/vcr_steps.rb +0 -252
  71. data/features/webmock.feature +0 -26
  72. data/full_build +0 -1
@@ -0,0 +1,38 @@
1
+ Feature: Error for HTTP request made when no cassette is in use
2
+
3
+ VCR is designed to help you remove all HTTP dependencies from your
4
+ test suite. To assist with this, VCR will cause an exception to be
5
+ raised when an HTTP request is made while there is no cassette in
6
+ use. The error is helpful to pinpoint where HTTP requests are
7
+ made so you can use a VCR cassette at that point in your code.
8
+
9
+ Scenario Outline: Error for request when no cassette is in use
10
+ Given a file named "no_cassette_error.rb" with:
11
+ """
12
+ require 'vcr_cucumber_helpers'
13
+ include_http_adapter_for("<http_lib>")
14
+
15
+ require 'vcr'
16
+
17
+ VCR.config do |c|
18
+ c.stub_with <stub_with>
19
+ c.cassette_library_dir = 'cassettes'
20
+ end
21
+
22
+ response_body_for(:get, 'http://example.com/')
23
+ """
24
+ When I run "ruby no_cassette_error.rb"
25
+ Then it should fail with "<error>"
26
+ And the output should contain each of the following:
27
+ | You can use VCR to automatically record this request and replay it later. |
28
+ | from no_cassette_error.rb:11 |
29
+
30
+ Examples:
31
+ | stub_with | http_lib | error |
32
+ | :fakeweb | net/http | Real HTTP connections are disabled |
33
+ | :webmock | net/http | Real HTTP connections are disabled |
34
+ | :webmock | httpclient | Real HTTP connections are disabled |
35
+ | :webmock | curb | Real HTTP connections are disabled |
36
+ | :webmock | patron | Real HTTP connections are disabled |
37
+ | :webmock | em-http-request | Real HTTP connections are disabled |
38
+ | :typhoeus | typhoeus | Real HTTP requests are not allowed |
@@ -0,0 +1,78 @@
1
+ Feature: :all record mode
2
+
3
+ The :all record mode records all requests and does not
4
+ replay any previously recorded responds.
5
+
6
+ This can be temporarily used to force VCR to re-record
7
+ a cassette (i.e. to ensure the responses are not out of date)
8
+ or can be used when you simply want to log all HTTP requests.
9
+
10
+ Background:
11
+ Given a file named "setup.rb" with:
12
+ """
13
+ require 'vcr_cucumber_helpers'
14
+
15
+ start_sinatra_app(:port => 7777) do
16
+ get('/') { 'Hello' }
17
+ get('/foo') { 'Goodbye' }
18
+ end
19
+
20
+ require 'vcr'
21
+
22
+ VCR.config do |c|
23
+ c.stub_with :fakeweb
24
+ c.cassette_library_dir = 'cassettes'
25
+ end
26
+ """
27
+ And a previously recorded cassette file "cassettes/example.yml" with:
28
+ """
29
+ ---
30
+ - !ruby/struct:VCR::HTTPInteraction
31
+ request: !ruby/struct:VCR::Request
32
+ method: :get
33
+ uri: http://localhost:7777/
34
+ body:
35
+ headers:
36
+ response: !ruby/struct:VCR::Response
37
+ status: !ruby/struct:VCR::ResponseStatus
38
+ code: 200
39
+ message: OK
40
+ headers:
41
+ content-type:
42
+ - text/html;charset=utf-8
43
+ content-length:
44
+ - "20"
45
+ body: old response
46
+ http_version: "1.1"
47
+ """
48
+
49
+ Scenario: Re-record previously recorded response
50
+ Given a file named "re_record.rb" with:
51
+ """
52
+ require 'setup'
53
+
54
+ VCR.use_cassette('example', :record => :all) do
55
+ response = Net::HTTP.get_response('localhost', '/', 7777)
56
+ puts "Response: #{response.body}"
57
+ end
58
+ """
59
+ When I run "ruby re_record.rb"
60
+ Then it should pass with "Response: Hello"
61
+ And the file "cassettes/example.yml" should contain "body: Hello"
62
+ But the file "cassettes/example.yml" should not contain "body: old response"
63
+
64
+ Scenario: Record new request
65
+ Given a file named "record_new.rb" with:
66
+ """
67
+ require 'setup'
68
+
69
+ VCR.use_cassette('example', :record => :all) do
70
+ response = Net::HTTP.get_response('localhost', '/foo', 7777)
71
+ puts "Response: #{response.body}"
72
+ end
73
+ """
74
+ When I run "ruby record_new.rb"
75
+ Then it should pass with "Response: Goodbye"
76
+ And the file "cassettes/example.yml" should contain each of these:
77
+ | body: old response |
78
+ | body: Goodbye |
@@ -0,0 +1,71 @@
1
+ Feature: :new_episodes record mode
2
+
3
+ The :new_episodes record mode replays previously recorded
4
+ requests and records new ones.
5
+
6
+ Background:
7
+ Given a file named "setup.rb" with:
8
+ """
9
+ require 'vcr_cucumber_helpers'
10
+
11
+ start_sinatra_app(:port => 7777) do
12
+ get('/') { 'Hello' }
13
+ end
14
+
15
+ require 'vcr'
16
+
17
+ VCR.config do |c|
18
+ c.stub_with :fakeweb
19
+ c.cassette_library_dir = 'cassettes'
20
+ end
21
+ """
22
+ And a previously recorded cassette file "cassettes/example.yml" with:
23
+ """
24
+ ---
25
+ - !ruby/struct:VCR::HTTPInteraction
26
+ request: !ruby/struct:VCR::Request
27
+ method: :get
28
+ uri: http://example.com:80/foo
29
+ body:
30
+ headers:
31
+ response: !ruby/struct:VCR::Response
32
+ status: !ruby/struct:VCR::ResponseStatus
33
+ code: 200
34
+ message: OK
35
+ headers:
36
+ content-type:
37
+ - text/html;charset=utf-8
38
+ content-length:
39
+ - "20"
40
+ body: example.com response
41
+ http_version: "1.1"
42
+ """
43
+
44
+ Scenario: Previously recorded responses are replayed
45
+ Given a file named "replay_recorded_response.rb" with:
46
+ """
47
+ require 'setup'
48
+
49
+ VCR.use_cassette('example', :record => :none) do
50
+ response = Net::HTTP.get_response('example.com', '/foo')
51
+ puts "Response: #{response.body}"
52
+ end
53
+ """
54
+ When I run "ruby replay_recorded_response.rb"
55
+ Then it should pass with "Response: example.com response"
56
+
57
+ Scenario: New requests get recorded
58
+ Given a file named "record_new_requests.rb" with:
59
+ """
60
+ require 'setup'
61
+
62
+ VCR.use_cassette('example', :record => :new_episodes) do
63
+ response = Net::HTTP.get_response('localhost', '/', 7777)
64
+ puts "Response: #{response.body}"
65
+ end
66
+ """
67
+ When I run "ruby record_new_requests.rb"
68
+ Then it should pass with "Response: Hello"
69
+ And the file "cassettes/example.yml" should contain each of these:
70
+ | body: example.com response |
71
+ | body: Hello |
@@ -0,0 +1,65 @@
1
+ Feature: :none record mode
2
+
3
+ The :none record mode allows previously recorded responses
4
+ to be replayed, but raises an error for any new requests.
5
+
6
+ This is useful when you code makes potentially dangerous
7
+ HTTP requests. The :none record mode guarantees that no
8
+ new HTTP requests will be made.
9
+
10
+ Background:
11
+ Given a file named "vcr_config.rb" with:
12
+ """
13
+ require 'vcr'
14
+
15
+ VCR.config do |c|
16
+ c.stub_with :fakeweb
17
+ c.cassette_library_dir = 'cassettes'
18
+ end
19
+ """
20
+ And a previously recorded cassette file "cassettes/example.yml" with:
21
+ """
22
+ ---
23
+ - !ruby/struct:VCR::HTTPInteraction
24
+ request: !ruby/struct:VCR::Request
25
+ method: :get
26
+ uri: http://example.com:80/foo
27
+ body:
28
+ headers:
29
+ response: !ruby/struct:VCR::Response
30
+ status: !ruby/struct:VCR::ResponseStatus
31
+ code: 200
32
+ message: OK
33
+ headers:
34
+ content-type:
35
+ - text/html;charset=utf-8
36
+ content-length:
37
+ - "5"
38
+ body: Hello
39
+ http_version: "1.1"
40
+ """
41
+
42
+ Scenario: Previously recorded responses are replayed
43
+ Given a file named "replay_recorded_response.rb" with:
44
+ """
45
+ require 'vcr_config'
46
+
47
+ VCR.use_cassette('example', :record => :none) do
48
+ response = Net::HTTP.get_response('example.com', '/foo')
49
+ puts "Response: #{response.body}"
50
+ end
51
+ """
52
+ When I run "ruby replay_recorded_response.rb"
53
+ Then it should pass with "Response: Hello"
54
+
55
+ Scenario: New requests are prevented
56
+ Given a file named "prevent_new_request.rb" with:
57
+ """
58
+ require 'vcr_config'
59
+
60
+ VCR.use_cassette('example', :record => :none) do
61
+ Net::HTTP.get_response('example.com', '/bar')
62
+ end
63
+ """
64
+ When I run "ruby prevent_new_request.rb"
65
+ Then it should fail with "Real HTTP connections are disabled. Unregistered request: GET http://example.com/bar"
@@ -0,0 +1,379 @@
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
+
99
+ Scenario Outline: match on host and path (to ignore query params)
100
+ Given a previously recorded cassette file "cassettes/example.yml" with:
101
+ """
102
+ ---
103
+ - !ruby/struct:VCR::HTTPInteraction
104
+ request: !ruby/struct:VCR::Request
105
+ method: :get
106
+ uri: http://bar.com:80/foo?date=2010-11-09
107
+ body:
108
+ headers:
109
+ response: !ruby/struct:VCR::Response
110
+ status: !ruby/struct:VCR::ResponseStatus
111
+ code: 200
112
+ message: OK
113
+ headers:
114
+ content-length:
115
+ - "16"
116
+ body: bar.com response
117
+ http_version: "1.1"
118
+ - !ruby/struct:VCR::HTTPInteraction
119
+ request: !ruby/struct:VCR::Request
120
+ method: :get
121
+ uri: http://foo.com:80/bar?date=2010-11-10
122
+ body:
123
+ headers:
124
+ response: !ruby/struct:VCR::Response
125
+ status: !ruby/struct:VCR::ResponseStatus
126
+ code: 200
127
+ message: OK
128
+ headers:
129
+ content-length:
130
+ - "16"
131
+ body: foo.com response
132
+ http_version: "1.1"
133
+ """
134
+ And a file named "host_path_matching.rb" with:
135
+ """
136
+ require 'vcr_cucumber_helpers'
137
+ include_http_adapter_for("<http_lib>")
138
+
139
+ require 'vcr'
140
+
141
+ VCR.config do |c|
142
+ c.stub_with <stub_with>
143
+ c.cassette_library_dir = 'cassettes'
144
+ end
145
+
146
+ VCR.use_cassette('example', :record => :none, :match_requests_on => [:host, :path]) do
147
+ puts response_body_for(:post, "http://foo.com/bar?date=#{Date.today.to_s}")
148
+ puts response_body_for(:put, "http://bar.com/foo?date=#{Date.today.to_s}")
149
+ end
150
+ """
151
+ When I run "ruby host_path_matching.rb"
152
+ Then it should pass with:
153
+ """
154
+ foo.com response
155
+ bar.com response
156
+ """
157
+
158
+ Examples:
159
+ | stub_with | http_lib |
160
+ | :fakeweb | net/http |
161
+ | :webmock | net/http |
162
+ | :webmock | httpclient |
163
+ | :webmock | patron |
164
+ | :webmock | curb |
165
+ | :webmock | em-http-request |
166
+ | :typhoeus | typhoeus |
167
+
168
+ Scenario Outline: match on request body
169
+ Given a previously recorded cassette file "cassettes/example.yml" with:
170
+ """
171
+ ---
172
+ - !ruby/struct:VCR::HTTPInteraction
173
+ request: !ruby/struct:VCR::Request
174
+ method: :post
175
+ uri: http://example.com:80/
176
+ body: a=1
177
+ headers:
178
+ content-type:
179
+ - application/x-www-form-urlencoded
180
+ response: !ruby/struct:VCR::Response
181
+ status: !ruby/struct:VCR::ResponseStatus
182
+ code: 200
183
+ message: OK
184
+ headers:
185
+ content-length:
186
+ - "12"
187
+ body: a=1 response
188
+ http_version: "1.1"
189
+ - !ruby/struct:VCR::HTTPInteraction
190
+ request: !ruby/struct:VCR::Request
191
+ method: :post
192
+ uri: http://example.com:80/
193
+ body: a=2
194
+ headers:
195
+ content-type:
196
+ - application/x-www-form-urlencoded
197
+ response: !ruby/struct:VCR::Response
198
+ status: !ruby/struct:VCR::ResponseStatus
199
+ code: 200
200
+ message: OK
201
+ headers:
202
+ content-length:
203
+ - "12"
204
+ body: a=2 response
205
+ http_version: "1.1"
206
+ """
207
+ And a file named "body_matching.rb" with:
208
+ """
209
+ require 'vcr_cucumber_helpers'
210
+ include_http_adapter_for("<http_lib>")
211
+
212
+ require 'vcr'
213
+
214
+ VCR.config do |c|
215
+ c.stub_with <stub_with>
216
+ c.cassette_library_dir = 'cassettes'
217
+ end
218
+
219
+ VCR.use_cassette('example', :record => :none, :match_requests_on => [:method, :uri, :body]) do
220
+ puts response_body_for(:post, "http://example.com/", 'a=2')
221
+ puts response_body_for(:post, "http://example.com/", 'a=1')
222
+ end
223
+ """
224
+ When I run "ruby body_matching.rb"
225
+ Then it should pass with:
226
+ """
227
+ a=2 response
228
+ a=1 response
229
+ """
230
+
231
+ Examples:
232
+ | stub_with | http_lib |
233
+ | :webmock | net/http |
234
+ | :webmock | httpclient |
235
+ | :webmock | patron |
236
+ | :webmock | curb |
237
+ | :webmock | em-http-request |
238
+ | :typhoeus | typhoeus |
239
+
240
+ Scenario Outline: match on request headers
241
+ Given a previously recorded cassette file "cassettes/example.yml" with:
242
+ """
243
+ ---
244
+ - !ruby/struct:VCR::HTTPInteraction
245
+ request: !ruby/struct:VCR::Request
246
+ method: :get
247
+ uri: http://example.com:80/dashboard
248
+ body:
249
+ headers:
250
+ x-user-id:
251
+ - "17"
252
+ response: !ruby/struct:VCR::Response
253
+ status: !ruby/struct:VCR::ResponseStatus
254
+ code: 200
255
+ message: OK
256
+ headers:
257
+ content-length:
258
+ - "16"
259
+ body: user 17 response
260
+ http_version: "1.1"
261
+ - !ruby/struct:VCR::HTTPInteraction
262
+ request: !ruby/struct:VCR::Request
263
+ method: :get
264
+ uri: http://example.com:80/dashboard
265
+ body:
266
+ headers:
267
+ x-user-id:
268
+ - "42"
269
+ response: !ruby/struct:VCR::Response
270
+ status: !ruby/struct:VCR::ResponseStatus
271
+ code: 200
272
+ message: OK
273
+ headers:
274
+ content-length:
275
+ - "16"
276
+ body: user 42 response
277
+ http_version: "1.1"
278
+ """
279
+ And a file named "header_matching.rb" with:
280
+ """
281
+ require 'vcr_cucumber_helpers'
282
+ include_http_adapter_for("<http_lib>")
283
+
284
+ require 'vcr'
285
+
286
+ VCR.config do |c|
287
+ c.stub_with <stub_with>
288
+ c.cassette_library_dir = 'cassettes'
289
+ end
290
+
291
+ VCR.use_cassette('example', :record => :none, :match_requests_on => [:method, :uri, :headers]) do
292
+ puts response_body_for(:get, "http://example.com/dashboard", nil, 'X-User-Id' => '42')
293
+ puts response_body_for(:get, "http://example.com/dashboard", nil, 'X-User-Id' => '17')
294
+ end
295
+ """
296
+ When I run "ruby header_matching.rb"
297
+ Then it should pass with:
298
+ """
299
+ user 42 response
300
+ user 17 response
301
+ """
302
+
303
+ Examples:
304
+ | stub_with | http_lib |
305
+ | :webmock | net/http |
306
+ | :webmock | httpclient |
307
+ | :webmock | patron |
308
+ | :webmock | curb |
309
+ | :webmock | em-http-request |
310
+ | :typhoeus | typhoeus |
311
+
312
+ Scenario Outline: Use a regex for the request URI
313
+ Given a previously recorded cassette file "cassettes/example.yml" with:
314
+ """
315
+ ---
316
+ - !ruby/struct:VCR::HTTPInteraction
317
+ request: !ruby/struct:VCR::Request
318
+ method: :get
319
+ uri: !ruby/regexp /^http:\/\/bar\.com\/foo/
320
+ body:
321
+ headers:
322
+ response: !ruby/struct:VCR::Response
323
+ status: !ruby/struct:VCR::ResponseStatus
324
+ code: 200
325
+ message: OK
326
+ headers:
327
+ content-length:
328
+ - "16"
329
+ body: bar.com response
330
+ http_version: "1.1"
331
+ - !ruby/struct:VCR::HTTPInteraction
332
+ request: !ruby/struct:VCR::Request
333
+ method: :get
334
+ uri: !ruby/regexp /^http:\/\/foo\.com\/bar/
335
+ body:
336
+ headers:
337
+ response: !ruby/struct:VCR::Response
338
+ status: !ruby/struct:VCR::ResponseStatus
339
+ code: 200
340
+ message: OK
341
+ headers:
342
+ content-length:
343
+ - "16"
344
+ body: foo.com response
345
+ http_version: "1.1"
346
+ """
347
+ And a file named "uri_regex_matching.rb" with:
348
+ """
349
+ require 'vcr_cucumber_helpers'
350
+ include_http_adapter_for("<http_lib>")
351
+
352
+ require 'vcr'
353
+
354
+ VCR.config do |c|
355
+ c.stub_with <stub_with>
356
+ c.cassette_library_dir = 'cassettes'
357
+ end
358
+
359
+ VCR.use_cassette('example', :record => :none) do
360
+ puts response_body_for(:get, "http://foo.com/bar?date=#{Date.today.to_s}")
361
+ puts response_body_for(:get, "http://bar.com/foo?date=#{Date.today.to_s}")
362
+ end
363
+ """
364
+ When I run "ruby uri_regex_matching.rb"
365
+ Then it should pass with:
366
+ """
367
+ foo.com response
368
+ bar.com response
369
+ """
370
+
371
+ Examples:
372
+ | stub_with | http_lib |
373
+ | :fakeweb | net/http |
374
+ | :webmock | net/http |
375
+ | :webmock | httpclient |
376
+ | :webmock | patron |
377
+ | :webmock | curb |
378
+ | :webmock | em-http-request |
379
+ | :typhoeus | typhoeus |