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,250 +0,0 @@
1
- @exclude-jruby @exclude-rbx
2
- Feature: EM HTTP Request
3
-
4
- EM HTTP Request allows multiple simultaneous asynchronous requests.
5
- (The other HTTP libraries are synchronous). The scenarios below
6
- demonstrate how VCR can be used with asynchronous em-http requests.
7
-
8
- Background:
9
- Given a file named "vcr_setup.rb" with:
10
- """ruby
11
- require 'em-http-request'
12
-
13
- $server = start_sinatra_app do
14
- %w[ foo bar bazz ].each_with_index do |path, index|
15
- get "/#{path}" do
16
- sleep index * 0.1 # ensure the async callbacks are invoked in order
17
- ARGV[0] + ' ' + path
18
- end
19
- end
20
- end
21
-
22
- require 'vcr'
23
-
24
- VCR.configure do |c|
25
- c.hook_into :webmock
26
- c.cassette_library_dir = 'cassettes'
27
- c.before_record do |i|
28
- i.request.uri.sub!(/:\d+/, ':7777')
29
- end
30
- end
31
- """
32
-
33
- Scenario: multiple simultaneous HttpRequest objects
34
- Given a file named "make_requests.rb" with:
35
- """ruby
36
- require 'vcr_setup'
37
-
38
- VCR.use_cassette('em_http') do
39
- EventMachine.run do
40
- http_array = %w[ foo bar bazz ].map do |p|
41
- EventMachine::HttpRequest.new("http://localhost:#{$server.port}/#{p}").get
42
- end
43
-
44
- http_array.each do |http|
45
- http.callback do
46
- puts http.response
47
-
48
- if http_array.all? { |h| h.response.to_s != '' }
49
- EventMachine.stop
50
- end
51
- end
52
- end
53
- end
54
- end
55
- """
56
- When I run `ruby make_requests.rb Hello`
57
- Then the output should contain:
58
- """
59
- Hello foo
60
- Hello bar
61
- Hello bazz
62
- """
63
- And the file "cassettes/em_http.yml" should contain YAML like:
64
- """
65
- ---
66
- http_interactions:
67
- - request:
68
- method: get
69
- uri: http://localhost:7777/foo
70
- body:
71
- encoding: UTF-8
72
- string: ""
73
- headers: {}
74
- response:
75
- status:
76
- code: 200
77
- message: OK
78
- headers:
79
- Content-Type:
80
- - text/html;charset=utf-8
81
- Content-Length:
82
- - "9"
83
- body:
84
- encoding: UTF-8
85
- string: Hello foo
86
- http_version:
87
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
88
- - request:
89
- method: get
90
- uri: http://localhost:7777/bar
91
- body:
92
- encoding: UTF-8
93
- string: ""
94
- headers: {}
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 bar
107
- http_version:
108
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
109
- - request:
110
- method: get
111
- uri: http://localhost:7777/bazz
112
- body:
113
- encoding: UTF-8
114
- string: ""
115
- headers: {}
116
- response:
117
- status:
118
- code: 200
119
- message: OK
120
- headers:
121
- Content-Type:
122
- - text/html;charset=utf-8
123
- Content-Length:
124
- - "10"
125
- body:
126
- encoding: UTF-8
127
- string: Hello bazz
128
- http_version:
129
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
130
- recorded_with: VCR 2.0.0
131
- """
132
-
133
- When I run `ruby make_requests.rb Goodbye`
134
- Then the output should contain:
135
- """
136
- Hello foo
137
- Hello bar
138
- Hello bazz
139
- """
140
-
141
- Scenario: MultiRequest
142
- Given a file named "make_requests.rb" with:
143
- """ruby
144
- require 'vcr_setup'
145
-
146
- VCR.use_cassette('em_http') do
147
- EventMachine.run do
148
- multi = EventMachine::MultiRequest.new
149
-
150
- %w[ foo bar bazz ].each do |path|
151
- multi.add(path, EventMachine::HttpRequest.new("http://localhost:#{$server.port}/#{path}").get)
152
- end
153
-
154
- multi.callback do
155
- responses = Hash[multi.responses[:callback]]
156
-
157
- %w[ foo bar bazz ].each do |path|
158
- puts responses[path].response
159
- end
160
-
161
- EventMachine.stop
162
- end
163
- end
164
- end
165
- """
166
- When I run `ruby make_requests.rb Hello`
167
- Then the output should contain:
168
- """
169
- Hello foo
170
- Hello bar
171
- Hello bazz
172
- """
173
- And the file "cassettes/em_http.yml" should contain YAML like:
174
- """
175
- ---
176
- http_interactions:
177
- - request:
178
- method: get
179
- uri: http://localhost:7777/foo
180
- body:
181
- encoding: UTF-8
182
- string: ""
183
- headers: {}
184
- response:
185
- status:
186
- code: 200
187
- message: OK
188
- headers:
189
- Content-Type:
190
- - text/html;charset=utf-8
191
- Content-Length:
192
- - "9"
193
- body:
194
- encoding: UTF-8
195
- string: Hello foo
196
- http_version:
197
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
198
- - request:
199
- method: get
200
- uri: http://localhost:7777/bar
201
- body:
202
- encoding: UTF-8
203
- string: ""
204
- headers: {}
205
- response:
206
- status:
207
- code: 200
208
- message: OK
209
- headers:
210
- Content-Type:
211
- - text/html;charset=utf-8
212
- Content-Length:
213
- - "9"
214
- body:
215
- encoding: UTF-8
216
- string: Hello bar
217
- http_version:
218
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
219
- - request:
220
- method: get
221
- uri: http://localhost:7777/bazz
222
- body:
223
- encoding: UTF-8
224
- string: ""
225
- headers: {}
226
- response:
227
- status:
228
- code: 200
229
- message: OK
230
- headers:
231
- Content-Type:
232
- - text/html;charset=utf-8
233
- Content-Length:
234
- - "10"
235
- body:
236
- encoding: UTF-8
237
- string: Hello bazz
238
- http_version:
239
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
240
- recorded_with: VCR 2.0.0
241
- """
242
-
243
- When I run `ruby make_requests.rb Goodbye`
244
- Then the output should contain:
245
- """
246
- Hello foo
247
- Hello bar
248
- Hello bazz
249
- """
250
-
@@ -1,179 +0,0 @@
1
- Feature: Net::HTTP
2
-
3
- There are many ways to use Net::HTTP. The scenarios below provide regression
4
- tests for some Net::HTTP APIs that have not worked properly with VCR and
5
- FakeWeb or WebMock in the past (but have since been fixed).
6
-
7
- Background:
8
- Given a file named "vcr_setup.rb" with:
9
- """ruby
10
- require 'ostruct'
11
-
12
- if ARGV[0] == '--with-server'
13
- $server = start_sinatra_app do
14
- get('/') { 'VCR works with Net::HTTP gets!' }
15
- post('/') { 'VCR works with Net::HTTP posts!' }
16
- end
17
- else
18
- $server = OpenStruct(:port => 0)
19
- end
20
-
21
- require 'vcr'
22
-
23
- VCR.configure do |c|
24
- c.default_cassette_options = {
25
- :match_requests_on => [:method, :host, :path]
26
- }
27
- end
28
- """
29
-
30
- Scenario Outline: Calling #post on new Net::HTTP instance
31
- Given a file named "vcr_net_http.rb" with:
32
- """ruby
33
- require 'vcr_setup.rb'
34
-
35
- VCR.configure do |c|
36
- c.hook_into <hook_into>
37
- c.cassette_library_dir = 'cassettes'
38
- end
39
-
40
- VCR.use_cassette('net_http') do
41
- puts Net::HTTP.new('localhost', $server.port).post('/', '').body
42
- end
43
- """
44
- When I run `ruby vcr_net_http.rb --with-server`
45
- Then the output should contain "VCR works with Net::HTTP posts!"
46
- And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP posts!"
47
-
48
- When I run `ruby vcr_net_http.rb`
49
- Then the output should contain "VCR works with Net::HTTP posts!"
50
-
51
- Examples:
52
- | hook_into |
53
- | :fakeweb |
54
- | :webmock |
55
-
56
- Scenario Outline: Return from yielded block
57
- Given a file named "vcr_net_http.rb" with:
58
- """ruby
59
- require 'vcr_setup.rb'
60
-
61
- VCR.configure do |c|
62
- c.hook_into <hook_into>
63
- c.cassette_library_dir = 'cassettes'
64
- end
65
-
66
- def perform_request
67
- Net::HTTP.new('localhost', $server.port).request(Net::HTTP::Get.new('/', {})) do |response|
68
- return response
69
- end
70
- end
71
-
72
- VCR.use_cassette('net_http') do
73
- puts perform_request.body
74
- end
75
- """
76
- When I run `ruby vcr_net_http.rb --with-server`
77
- Then the output should contain "VCR works with Net::HTTP gets!"
78
- And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
79
-
80
- When I run `ruby vcr_net_http.rb`
81
- Then the output should contain "VCR works with Net::HTTP gets!"
82
-
83
- Examples:
84
- | hook_into |
85
- | :fakeweb |
86
- | :webmock |
87
-
88
- Scenario Outline: Use Net::ReadAdapter to read body in fragments
89
- Given a file named "vcr_net_http.rb" with:
90
- """ruby
91
- require 'vcr_setup.rb'
92
-
93
- VCR.configure do |c|
94
- c.hook_into <hook_into>
95
- c.cassette_library_dir = 'cassettes'
96
- end
97
-
98
- VCR.use_cassette('net_http') do
99
- body = ''
100
-
101
- Net::HTTP.new('localhost', $server.port).request_get('/') do |response|
102
- response.read_body { |frag| body << frag }
103
- end
104
-
105
- puts body
106
- end
107
- """
108
- When I run `ruby vcr_net_http.rb --with-server`
109
- Then the output should contain "VCR works with Net::HTTP gets!"
110
- And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
111
-
112
- When I run `ruby vcr_net_http.rb`
113
- Then the output should contain "VCR works with Net::HTTP gets!"
114
-
115
- Examples:
116
- | hook_into |
117
- | :fakeweb |
118
- | :webmock |
119
-
120
- Scenario Outline: Use open-uri (which is built on top of Net::HTTP and uses a seldom-used Net::HTTP API)
121
- Given a file named "vcr_net_http.rb" with:
122
- """ruby
123
- require 'open-uri'
124
- require 'vcr_setup.rb'
125
-
126
- VCR.configure do |c|
127
- c.hook_into <hook_into>
128
- c.cassette_library_dir = 'cassettes'
129
- end
130
-
131
- VCR.use_cassette('net_http') do
132
- puts open("http://localhost:#{$server.port}/").read
133
- end
134
- """
135
- When I run `ruby vcr_net_http.rb --with-server`
136
- Then the output should contain "VCR works with Net::HTTP gets!"
137
- And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
138
-
139
- When I run `ruby vcr_net_http.rb`
140
- Then the output should contain "VCR works with Net::HTTP gets!"
141
-
142
- Examples:
143
- | hook_into |
144
- | :fakeweb |
145
- | :webmock |
146
-
147
- Scenario Outline: Make an HTTPS request
148
- Given a file named "vcr_https.rb" with:
149
- """ruby
150
- require 'vcr'
151
-
152
- VCR.configure do |c|
153
- c.hook_into <hook_into>
154
- c.cassette_library_dir = 'cassettes'
155
- end
156
-
157
- uri = URI("https://gist.githubusercontent.com/myronmarston/fb555cb593f3349d53af/raw/6921dd638337d3f6a51b0e02e7f30e3c414f70d6/vcr_gist")
158
-
159
- VCR.use_cassette('https') do
160
- http = Net::HTTP.new(uri.host, uri.port)
161
- http.use_ssl = true
162
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
163
- response = http.request_get(uri.path)
164
-
165
- puts response.body
166
- end
167
- """
168
- When I run `ruby vcr_https.rb`
169
- Then the output should contain "VCR gist"
170
- And the file "cassettes/https.yml" should contain "VCR gist"
171
-
172
- When I modify the file "cassettes/https.yml" to replace "VCR gist" with "HTTPS replaying works"
173
- And I run `ruby vcr_https.rb`
174
- Then the output should contain "HTTPS replaying works"
175
-
176
- Examples:
177
- | hook_into |
178
- | :fakeweb |
179
- | :webmock |
@@ -1,56 +0,0 @@
1
- Feature: Faraday middleware
2
-
3
- VCR provides middleware that can be used with Faraday. You can use this as
4
- an alternative to Faraday's built-in test adapter.
5
-
6
- VCR will automatically insert this middleware in the Faraday stack
7
- when you configure `hook_into :faraday`. However, if you want to control
8
- where the middleware goes in the faraday stack, you can use it yourself.
9
- The middleware should come before the Faraday HTTP adapter.
10
-
11
- Note that when you use the middleware directly, you don't need to configure
12
- `hook_into :faraday`.
13
-
14
- Scenario Outline: Use Faraday middleware
15
- Given a file named "faraday_example.rb" with:
16
- """ruby
17
- request_count = 0
18
- $server = start_sinatra_app do
19
- get('/:path') { "Hello #{params[:path]} #{request_count += 1}" }
20
- end
21
-
22
- require 'faraday'
23
- require 'vcr'
24
- <extra_require>
25
-
26
- VCR.configure do |c|
27
- c.default_cassette_options = { :serialize_with => :syck }
28
- c.cassette_library_dir = 'cassettes'
29
- end
30
-
31
- conn = Faraday::Connection.new(:url => "http://localhost:#{$server.port}") do |builder|
32
- builder.use VCR::Middleware::Faraday
33
- builder.adapter :<adapter>
34
- end
35
-
36
- VCR.use_cassette('example') do
37
- puts "Response 1: #{conn.get('/foo').body}"
38
- end
39
-
40
- VCR.use_cassette('example') do
41
- puts "Response 2: #{conn.get('/foo').body}"
42
- end
43
- """
44
- When I run `ruby faraday_example.rb`
45
- Then the output should contain:
46
- """
47
- Response 1: Hello foo 1
48
- Response 2: Hello foo 1
49
- """
50
- And the file "cassettes/example.yml" should contain "Hello foo 1"
51
-
52
- Examples:
53
- | adapter | extra_require |
54
- | net_http | |
55
- | typhoeus | require 'typhoeus/adapters/faraday' |
56
-
@@ -1,92 +0,0 @@
1
- Feature: Rack
2
-
3
- VCR provides a rack middleware that uses a cassette for the duration of
4
- a request. Simply provide `VCR::Middleware::Rack` with a block that sets
5
- the cassette name and options. You can set these based on the rack env
6
- if your block accepts two arguments.
7
-
8
- This is useful in a couple different ways:
9
-
10
- - In a rails app, you could use this to log all HTTP API calls made by
11
- the rails app (using the `:all` record mode). Of course, this will only
12
- record HTTP API calls made in the request-response cycle--API calls that
13
- are offloaded to a background job will not be logged.
14
- - This can be used as middleware in a simple rack HTTP proxy, to record
15
- and replay the proxied requests.
16
-
17
- Background:
18
- Given a file named "remote_server.rb" with:
19
- """ruby
20
- request_count = 0
21
- $server = start_sinatra_app do
22
- get('/:path') { "Hello #{params[:path]} #{request_count += 1}" }
23
- end
24
- """
25
- And a file named "client.rb" with:
26
- """ruby
27
- require 'remote_server'
28
- require 'proxy_server'
29
- require 'cgi'
30
-
31
- url = URI.parse("http://localhost:#{$proxy.port}?url=#{CGI.escape("http://localhost:#{$server.port}/foo")}")
32
-
33
- puts "Response 1: #{Net::HTTP.get_response(url).body}"
34
- puts "Response 2: #{Net::HTTP.get_response(url).body}"
35
- """
36
- And the directory "cassettes" does not exist
37
-
38
- Scenario: Use VCR rack middleware to record HTTP responses for a simple rack proxy app
39
- Given a file named "proxy_server.rb" with:
40
- """ruby
41
- require 'vcr'
42
-
43
- $proxy = start_sinatra_app do
44
- use VCR::Middleware::Rack do |cassette|
45
- cassette.name 'proxied'
46
- cassette.options :record => :new_episodes
47
- end
48
-
49
- get('/') { Net::HTTP.get_response(URI.parse(params[:url])).body }
50
- end
51
-
52
- VCR.configure do |c|
53
- c.cassette_library_dir = 'cassettes'
54
- c.hook_into :webmock
55
- c.allow_http_connections_when_no_cassette = true
56
- end
57
- """
58
- When I run `ruby client.rb`
59
- Then the output should contain:
60
- """
61
- Response 1: Hello foo 1
62
- Response 2: Hello foo 1
63
- """
64
- And the file "cassettes/proxied.yml" should contain "Hello foo 1"
65
-
66
- Scenario: Set cassette name based on rack request env
67
- Given a file named "proxy_server.rb" with:
68
- """ruby
69
- require 'vcr'
70
-
71
- $proxy = start_sinatra_app do
72
- use VCR::Middleware::Rack do |cassette, env|
73
- cassette.name env['SERVER_NAME']
74
- end
75
-
76
- get('/') { Net::HTTP.get_response(URI.parse(params[:url])).body }
77
- end
78
-
79
- VCR.configure do |c|
80
- c.cassette_library_dir = 'cassettes'
81
- c.hook_into :webmock
82
- c.allow_http_connections_when_no_cassette = true
83
- end
84
- """
85
- When I run `ruby client.rb`
86
- Then the output should contain:
87
- """
88
- Response 1: Hello foo 1
89
- Response 2: Hello foo 1
90
- """
91
- And the file "cassettes/localhost.yml" should contain "Hello foo 1"
92
-
@@ -1,82 +0,0 @@
1
- Feature: :all
2
-
3
- The `:all` record mode will:
4
-
5
- - Record new interactions.
6
- - Never replay previously recorded interactions.
7
-
8
- This can be temporarily used to force VCR to re-record
9
- a cassette (i.e. to ensure the responses are not out of date)
10
- or can be used when you simply want to log all HTTP requests.
11
-
12
- Background:
13
- Given a file named "setup.rb" with:
14
- """ruby
15
- $server = start_sinatra_app do
16
- get('/') { 'Hello' }
17
- get('/foo') { 'Goodbye' }
18
- end
19
-
20
- require 'vcr'
21
-
22
- VCR.configure do |c|
23
- c.hook_into :webmock
24
- c.cassette_library_dir = 'cassettes'
25
- end
26
- """
27
- And a previously recorded cassette file "cassettes/example.yml" with:
28
- """
29
- ---
30
- http_interactions:
31
- - request:
32
- method: get
33
- uri: http://localhost/
34
- body:
35
- encoding: UTF-8
36
- string: ""
37
- headers: {}
38
- response:
39
- status:
40
- code: 200
41
- message: OK
42
- headers:
43
- Content-Length:
44
- - "20"
45
- body:
46
- encoding: UTF-8
47
- string: old response
48
- http_version: "1.1"
49
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
50
- recorded_with: VCR 2.0.0
51
- """
52
-
53
- Scenario: Re-record previously recorded response
54
- Given a file named "re_record.rb" with:
55
- """ruby
56
- require 'setup'
57
-
58
- VCR.use_cassette('example', :record => :all, :match_requests_on => [:method, :host, :path]) do
59
- response = Net::HTTP.get_response('localhost', '/', $server.port)
60
- puts "Response: #{response.body}"
61
- end
62
- """
63
- When I run `ruby re_record.rb`
64
- Then it should pass with "Response: Hello"
65
- And the file "cassettes/example.yml" should contain "Hello"
66
- But the file "cassettes/example.yml" should not contain "old response"
67
-
68
- Scenario: Record new request
69
- Given a file named "record_new.rb" with:
70
- """ruby
71
- require 'setup'
72
-
73
- VCR.use_cassette('example', :record => :all) do
74
- response = Net::HTTP.get_response('localhost', '/foo', $server.port)
75
- puts "Response: #{response.body}"
76
- end
77
- """
78
- When I run `ruby record_new.rb`
79
- Then it should pass with "Response: Goodbye"
80
- And the file "cassettes/example.yml" should contain each of these:
81
- | old response |
82
- | Goodbye |