vcr 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +63 -46
- data/README.md +5 -2
- data/features/cassettes/allow_unused_http_interactions.feature +1 -1
- data/features/cassettes/automatic_re_recording.feature +1 -1
- data/features/cassettes/decompress.feature +3 -3
- data/features/cassettes/dynamic_erb.feature +2 -2
- data/features/cassettes/exclusive.feature +1 -1
- data/features/cassettes/naming.feature +1 -1
- data/features/cassettes/no_cassette.feature +6 -3
- data/features/cassettes/persistence.feature +1 -1
- data/features/cassettes/update_content_length_header.feature +1 -1
- data/features/configuration/allow_http_connections_when_no_cassette.feature +1 -1
- data/features/configuration/cassette_library_dir.feature +1 -1
- data/features/configuration/debug_logging.feature +5 -5
- data/features/configuration/filter_sensitive_data.feature +2 -2
- data/features/configuration/hook_into.feature +4 -7
- data/features/getting_started.md +2 -2
- data/features/hooks/before_playback.feature +5 -5
- data/features/hooks/before_record.feature +5 -5
- data/features/middleware/rack.feature +2 -2
- data/features/record_modes/all.feature +1 -1
- data/features/record_modes/new_episodes.feature +1 -1
- data/features/record_modes/none.feature +1 -1
- data/features/record_modes/once.feature +1 -1
- data/features/request_matching/custom_matcher.feature +1 -1
- data/features/request_matching/headers.feature +0 -2
- data/features/request_matching/playback_repeats.feature +1 -1
- data/features/request_matching/uri_without_param.feature +1 -1
- data/features/support/env.rb +1 -0
- data/features/test_frameworks/cucumber.feature +8 -8
- data/features/test_frameworks/rspec_macro.feature +2 -2
- data/features/test_frameworks/rspec_metadata.feature +1 -1
- data/gemfiles/typhoeus_old.gemfile +1 -1
- data/gemfiles/typhoeus_old.gemfile.lock +31 -57
- data/lib/vcr/cassette/migrator.rb +8 -1
- data/lib/vcr/configuration.rb +9 -2
- data/lib/vcr/library_hooks/excon.rb +2 -184
- data/lib/vcr/library_hooks/typhoeus.rb +1 -1
- data/lib/vcr/library_hooks/typhoeus_0.4.rb +4 -0
- data/lib/vcr/library_hooks/webmock.rb +1 -1
- data/lib/vcr/middleware/excon.rb +226 -0
- data/lib/vcr/version.rb +1 -1
- data/spec/acceptance/threading_spec.rb +28 -0
- data/spec/monkey_patches.rb +3 -7
- data/spec/quality_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -4
- data/spec/support/http_library_adapters.rb +4 -3
- data/spec/support/shared_example_groups/excon.rb +22 -0
- data/spec/support/shared_example_groups/hook_into_http_library.rb +46 -46
- data/spec/support/shared_example_groups/request_hooks.rb +8 -8
- data/spec/vcr/cassette/erb_renderer_spec.rb +5 -5
- data/spec/vcr/cassette/http_interaction_list_spec.rb +52 -40
- data/spec/vcr/cassette/migrator_spec.rb +11 -11
- data/spec/vcr/cassette/persisters/file_system_spec.rb +11 -11
- data/spec/vcr/cassette/persisters_spec.rb +2 -2
- data/spec/vcr/cassette/serializers_spec.rb +13 -12
- data/spec/vcr/cassette_spec.rb +58 -58
- data/spec/vcr/configuration_spec.rb +43 -31
- data/spec/vcr/deprecations_spec.rb +3 -3
- data/spec/vcr/errors_spec.rb +25 -25
- data/spec/vcr/extensions/net_http_response_spec.rb +7 -7
- data/spec/vcr/library_hooks/excon_spec.rb +7 -85
- data/spec/vcr/library_hooks/fakeweb_spec.rb +15 -13
- data/spec/vcr/library_hooks/faraday_spec.rb +4 -4
- data/spec/vcr/library_hooks/typhoeus_0.4_spec.rb +5 -0
- data/spec/vcr/library_hooks/typhoeus_spec.rb +3 -3
- data/spec/vcr/library_hooks/webmock_spec.rb +13 -5
- data/spec/vcr/library_hooks_spec.rb +9 -9
- data/spec/vcr/middleware/faraday_spec.rb +10 -10
- data/spec/vcr/middleware/rack_spec.rb +20 -15
- data/spec/vcr/request_ignorer_spec.rb +3 -3
- data/spec/vcr/request_matcher_registry_spec.rb +88 -61
- data/spec/vcr/structs_spec.rb +85 -85
- data/spec/vcr/test_frameworks/cucumber_spec.rb +7 -7
- data/spec/vcr/test_frameworks/rspec_spec.rb +10 -10
- data/spec/vcr/util/hooks_spec.rb +20 -20
- data/spec/vcr/util/internet_connection_spec.rb +2 -2
- data/spec/vcr_spec.rb +50 -48
- data/vcr.gemspec +4 -4
- metadata +308 -372
data/lib/vcr/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VCR do
|
4
|
+
context 'when used in a multithreaded environment', :with_monkey_patches => :excon do
|
5
|
+
def recorded_content_for(name)
|
6
|
+
VCR.cassette_persisters[:file_system]["#{name}.yml"].to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can use a cassette in an #around_http_request hook', :if => (RUBY_VERSION.to_f > 1.8) do
|
10
|
+
VCR.configure do |vcr|
|
11
|
+
vcr.around_http_request do |req|
|
12
|
+
VCR.use_cassette(req.parsed_uri.path, &req)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
thread = Thread.start do
|
17
|
+
Excon.get "http://localhost:#{VCR::SinatraApp.port}/search?q=thread"
|
18
|
+
end
|
19
|
+
|
20
|
+
Excon.get "http://localhost:#{VCR::SinatraApp.port}/foo",
|
21
|
+
:response_block => Proc.new { thread.join }
|
22
|
+
|
23
|
+
expect(recorded_content_for("search") +
|
24
|
+
recorded_content_for("foo")).to include("query: thread", "FOO!")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/spec/monkey_patches.rb
CHANGED
@@ -42,10 +42,7 @@ module MonkeyPatches
|
|
42
42
|
::Typhoeus::Hydra.stub_finders << finder
|
43
43
|
end
|
44
44
|
when :excon
|
45
|
-
|
46
|
-
::Excon.stubs << stub
|
47
|
-
end
|
48
|
-
::Excon.defaults[:mock] = true
|
45
|
+
::Excon.defaults[:middlewares] << VCR::Middleware::Excon
|
49
46
|
when :vcr
|
50
47
|
realias Net::HTTP, :request, :with_vcr
|
51
48
|
else raise ArgumentError.new("Unexpected scope: #{scope}")
|
@@ -72,8 +69,7 @@ module MonkeyPatches
|
|
72
69
|
end
|
73
70
|
|
74
71
|
if defined?(::Excon)
|
75
|
-
::Excon.
|
76
|
-
::Excon.defaults[:mock] = false
|
72
|
+
::Excon.defaults[:middlewares].delete(VCR::Middleware::Excon)
|
77
73
|
end
|
78
74
|
end
|
79
75
|
|
@@ -150,6 +146,7 @@ if defined?(::Typhoeus.before)
|
|
150
146
|
$original_typhoeus_before_hooks = Typhoeus.before.dup
|
151
147
|
elsif defined?(::Typhoeus::Hydra.global_hooks)
|
152
148
|
require 'vcr/library_hooks/typhoeus'
|
149
|
+
$typhoeus_0_4_after_loaded_hook = VCR.configuration.hooks[:after_library_hooks_loaded].first
|
153
150
|
$typhoeus_after_loaded_hook = VCR.configuration.hooks[:after_library_hooks_loaded].last
|
154
151
|
$original_typhoeus_global_hooks = Typhoeus::Hydra.global_hooks.dup
|
155
152
|
$original_typhoeus_stub_finders = Typhoeus::Hydra.stub_finders.dup
|
@@ -171,7 +168,6 @@ $original_webmock_callbacks = ::WebMock::CallbackRegistry.callbacks
|
|
171
168
|
|
172
169
|
require 'vcr/library_hooks/excon'
|
173
170
|
$excon_after_loaded_hook = VCR.configuration.hooks[:after_library_hooks_loaded].last
|
174
|
-
$original_excon_stubs = ::Excon.stubs.dup
|
175
171
|
|
176
172
|
# disable all by default; we'll enable specific ones when we need them
|
177
173
|
MonkeyPatches.disable_all!
|
data/spec/quality_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
+
using_git = File.exist?(File.expand_path('../../.git/', __FILE__))
|
4
|
+
require 'bundler/setup' if using_git
|
5
|
+
|
3
6
|
if RUBY_VERSION =~ /1.9/ && RUBY_ENGINE == 'ruby'
|
4
7
|
require 'simplecov'
|
5
8
|
|
@@ -22,9 +25,6 @@ if RUBY_VERSION =~ /1.9/ && RUBY_ENGINE == 'ruby'
|
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
|
-
using_git = File.exist?(File.expand_path('../../.git/', __FILE__))
|
26
|
-
require 'bundler/setup' if using_git
|
27
|
-
|
28
28
|
require 'rspec'
|
29
29
|
|
30
30
|
require "support/fixnum_extension"
|
@@ -54,9 +54,12 @@ end
|
|
54
54
|
RSpec.configure do |config|
|
55
55
|
config.order = :rand
|
56
56
|
config.color_enabled = true
|
57
|
-
config.debug = (using_git && RUBY_INTERPRETER == :mri && !%w[ 1.9.3 ].include?(RUBY_VERSION) && !ENV['CI'])
|
58
57
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
59
58
|
|
59
|
+
config.expect_with :rspec do |expectations|
|
60
|
+
expectations.syntax = :expect
|
61
|
+
end
|
62
|
+
|
60
63
|
tmp_dir = File.expand_path('../../tmp/cassette_library_dir', __FILE__)
|
61
64
|
config.before(:each) do
|
62
65
|
unless example.metadata[:skip_vcr_reset]
|
@@ -35,7 +35,8 @@ HTTP_LIBRARY_ADAPTERS['net/http'] = Module.new do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
DEFAULT_REQUEST_HEADERS = { "Accept"=>["*/*"] }
|
38
|
-
DEFAULT_REQUEST_HEADERS['User-Agent'] = ["Ruby"] if RUBY_VERSION
|
38
|
+
DEFAULT_REQUEST_HEADERS['User-Agent'] = ["Ruby"] if RUBY_VERSION.to_f > 1.8
|
39
|
+
DEFAULT_REQUEST_HEADERS['Accept-Encoding'] = ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"] if RUBY_VERSION.to_f > 1.9
|
39
40
|
|
40
41
|
def normalize_request_headers(headers)
|
41
42
|
defined?(super) ? super :
|
@@ -218,7 +219,7 @@ HTTP_LIBRARY_ADAPTERS['excon'] = Module.new do
|
|
218
219
|
def make_http_request(method, url, body = nil, headers = {})
|
219
220
|
# There are multiple ways to use Excon but this is how fog (the main user of excon) uses it:
|
220
221
|
# https://github.com/fog/fog/blob/v1.1.1/lib/fog/aws/rds.rb#L139-147
|
221
|
-
Excon
|
222
|
+
Excon.new(url).request(:method => method.to_s.upcase, :body => body, :headers => headers)
|
222
223
|
end
|
223
224
|
|
224
225
|
def normalize_request_headers(headers)
|
@@ -277,7 +278,7 @@ end
|
|
277
278
|
end
|
278
279
|
|
279
280
|
def normalize_request_headers(headers)
|
280
|
-
headers
|
281
|
+
headers.merge("User-Agent" => ["Faraday v#{Faraday::VERSION}"])
|
281
282
|
end
|
282
283
|
end
|
283
284
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
shared_examples "Excon streaming" do
|
2
|
+
context "when Excon's streaming API is used" do
|
3
|
+
it 'properly records and plays back the response' do
|
4
|
+
VCR.stub(:real_http_connections_allowed? => true)
|
5
|
+
recorded, played_back = [1, 2].map do
|
6
|
+
chunks = []
|
7
|
+
|
8
|
+
VCR.use_cassette('excon_streaming', :record => :once) do
|
9
|
+
Excon.get "http://localhost:#{VCR::SinatraApp.port}/foo", :response_block => lambda { |chunk, remaining_bytes, total_bytes|
|
10
|
+
chunks << chunk
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
chunks.join
|
15
|
+
end
|
16
|
+
|
17
|
+
expect(recorded).to eq(played_back)
|
18
|
+
expect(recorded).to eq("FOO!")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -28,9 +28,9 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'returns the same header value when recording and replaying' do
|
31
|
-
(recorded_val = get_set_cookie_header).
|
31
|
+
expect((recorded_val = get_set_cookie_header)).not_to be_nil
|
32
32
|
replayed_val = get_set_cookie_header
|
33
|
-
replayed_val.
|
33
|
+
expect(replayed_val).to eq(recorded_val)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -46,7 +46,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
46
46
|
it "properly records and playsback a request with a URL #{description}" do
|
47
47
|
recorded_body = get_body
|
48
48
|
played_back_body = get_body
|
49
|
-
played_back_body.
|
49
|
+
expect(played_back_body).to eq(recorded_body)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -65,7 +65,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
65
65
|
|
66
66
|
recorded = get_body.call
|
67
67
|
played_back = get_body.call
|
68
|
-
played_back.
|
68
|
+
expect(played_back).to eq(recorded)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -83,7 +83,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
83
83
|
let(:response) { VCR::Response.new(status, nil, response_body, '1.1') }
|
84
84
|
|
85
85
|
it 'returns the response for a matching request' do
|
86
|
-
get_body_string(make_http_request(:get, 'http://example.com/')).
|
86
|
+
expect(get_body_string(make_http_request(:get, 'http://example.com/'))).to eq(response_body)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -93,7 +93,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
93
93
|
let(:response) { VCR::Response.new(status, nil, response_body, '1.1') }
|
94
94
|
|
95
95
|
it 'returns the expected response for the same request' do
|
96
|
-
get_body_string(make_http_request(:get, url)).
|
96
|
+
expect(get_body_string(make_http_request(:get, url))).to eq(response_body)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
@@ -118,7 +118,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
118
118
|
VCR.insert_cassette('foo')
|
119
119
|
make_http_request(:get, "http://localhost:#{VCR::SinatraApp.port}/foo")
|
120
120
|
|
121
|
-
call_count.
|
121
|
+
expect(call_count).to eq(1)
|
122
122
|
end
|
123
123
|
|
124
124
|
describe "using the library's stubbing/disconnection APIs" do
|
@@ -128,7 +128,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
128
128
|
it 'can make a real request when VCR is turned off' do
|
129
129
|
enable_real_connections
|
130
130
|
VCR.turn_off!
|
131
|
-
get_body_string(make_http_request(:get, request_url)).
|
131
|
+
expect(get_body_string(make_http_request(:get, request_url))).to eq("FOO!")
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'does not mess with VCR when real connections are disabled' do
|
@@ -136,7 +136,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
136
136
|
disable_real_connections
|
137
137
|
|
138
138
|
VCR.should_receive(:record_http_interaction) do |interaction|
|
139
|
-
interaction.request.uri.
|
139
|
+
expect(interaction.request.uri).to eq(request_url)
|
140
140
|
end
|
141
141
|
|
142
142
|
make_http_request(:get, request_url)
|
@@ -156,28 +156,28 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
156
156
|
it 'can directly stub the request when VCR is turned off' do
|
157
157
|
VCR.turn_off!
|
158
158
|
directly_stub_request(:get, request_url, "stubbed response")
|
159
|
-
get_body_string(make_http_request(:get, request_url)).
|
159
|
+
expect(get_body_string(make_http_request(:get, request_url))).to eq("stubbed response")
|
160
160
|
end
|
161
161
|
|
162
162
|
it 'can directly stub the request when VCR is turned on and no cassette is in use' do
|
163
163
|
directly_stub_request(:get, request_url, "stubbed response")
|
164
|
-
get_body_string(make_http_request(:get, request_url)).
|
164
|
+
expect(get_body_string(make_http_request(:get, request_url))).to eq("stubbed response")
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'can directly stub the request when VCR is turned on and a cassette is in use' do
|
168
168
|
VCR.use_cassette("temp") do
|
169
169
|
directly_stub_request(:get, request_url, "stubbed response")
|
170
|
-
get_body_string(make_http_request(:get, request_url)).
|
170
|
+
expect(get_body_string(make_http_request(:get, request_url))).to eq("stubbed response")
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'does not record requests that are directly stubbed' do
|
175
|
-
VCR.
|
175
|
+
expect(VCR).to respond_to(:record_http_interaction)
|
176
176
|
VCR.should_not_receive(:record_http_interaction)
|
177
177
|
|
178
178
|
VCR.use_cassette("temp") do
|
179
179
|
directly_stub_request(:get, request_url, "stubbed response")
|
180
|
-
get_body_string(make_http_request(:get, request_url)).
|
180
|
+
expect(get_body_string(make_http_request(:get, request_url))).to eq("stubbed response")
|
181
181
|
end
|
182
182
|
end
|
183
183
|
end
|
@@ -198,8 +198,8 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
198
198
|
make_http_request(:get, request_url)
|
199
199
|
end
|
200
200
|
|
201
|
-
yielded_request.method.
|
202
|
-
yielded_request.uri.
|
201
|
+
expect(yielded_request.method).to eq(:get)
|
202
|
+
expect(yielded_request.uri).to eq(request_url)
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'returns the response from request.proceed' do
|
@@ -212,7 +212,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
212
212
|
make_http_request(:get, request_url)
|
213
213
|
end
|
214
214
|
|
215
|
-
response.body.
|
215
|
+
expect(response.body).to eq("FOO!")
|
216
216
|
end
|
217
217
|
|
218
218
|
it 'can be used to use a cassette for a request' do
|
@@ -221,12 +221,12 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
221
221
|
end
|
222
222
|
|
223
223
|
VCR.should_receive(:record_http_interaction) do
|
224
|
-
VCR.current_cassette.name.
|
224
|
+
expect(VCR.current_cassette.name).to eq('new_cassette')
|
225
225
|
end
|
226
226
|
|
227
|
-
VCR.current_cassette.
|
227
|
+
expect(VCR.current_cassette).to be_nil
|
228
228
|
make_http_request(:get, request_url)
|
229
|
-
VCR.current_cassette.
|
229
|
+
expect(VCR.current_cassette).to be_nil
|
230
230
|
end
|
231
231
|
|
232
232
|
it 'nests them inside each other, making the first declared hook the outermost' do
|
@@ -249,7 +249,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
249
249
|
|
250
250
|
make_http_request(:get, request_url)
|
251
251
|
|
252
|
-
order.
|
252
|
+
expect(order).to eq([:before_1, :before_2, :after_2, :after_1])
|
253
253
|
end
|
254
254
|
|
255
255
|
it 'raises an appropriate error if the hook does not call request.proceed' do
|
@@ -260,8 +260,8 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
260
260
|
expect {
|
261
261
|
make_http_request(:get, request_url)
|
262
262
|
}.to raise_error { |error|
|
263
|
-
error.message.
|
264
|
-
error.message.
|
263
|
+
expect(error.message).to include('must call #proceed on the yielded request')
|
264
|
+
expect(error.message).to include(hook_declaration)
|
265
265
|
}
|
266
266
|
end
|
267
267
|
|
@@ -291,7 +291,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
291
291
|
end
|
292
292
|
|
293
293
|
make_http_request(:get, request_url)
|
294
|
-
order.
|
294
|
+
expect(order).to eq([:before_foo, :after_foo])
|
295
295
|
end
|
296
296
|
|
297
297
|
it 'ensures that both around/before are invoked or neither' do
|
@@ -313,7 +313,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
313
313
|
end
|
314
314
|
|
315
315
|
make_http_request(:get, request_url)
|
316
|
-
order.
|
316
|
+
expect(order).to eq([:before_1, :after_1])
|
317
317
|
end
|
318
318
|
end if RUBY_VERSION >= '1.9'
|
319
319
|
|
@@ -330,8 +330,8 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
330
330
|
end
|
331
331
|
|
332
332
|
make_http_request(:get, "http://localhost:#{VCR::SinatraApp.port}/foo")
|
333
|
-
before_type.
|
334
|
-
after_type.
|
333
|
+
expect(before_type).to be(:unhandled)
|
334
|
+
expect(after_type).to be(:recordable)
|
335
335
|
end
|
336
336
|
|
337
337
|
context "when the request is ignored" do
|
@@ -364,18 +364,18 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
364
364
|
VCR.insert_cassette('fake_example_responses', :record => :none)
|
365
365
|
end
|
366
366
|
end
|
367
|
-
get_body_string(make_http_request(:get, 'http://example.com/foo')).
|
367
|
+
expect(get_body_string(make_http_request(:get, 'http://example.com/foo'))).to eq(string_in_cassette)
|
368
368
|
end
|
369
369
|
|
370
370
|
specify 'the after_http_request hook can be used to eject a cassette after the request is recorded' do
|
371
371
|
VCR.configuration.after_http_request { |request| VCR.eject_cassette }
|
372
372
|
|
373
373
|
VCR.should_receive(:record_http_interaction) do |interaction|
|
374
|
-
VCR.current_cassette.
|
374
|
+
expect(VCR.current_cassette).to be(inserted_cassette)
|
375
375
|
end
|
376
376
|
|
377
377
|
make_request
|
378
|
-
VCR.current_cassette.
|
378
|
+
expect(VCR.current_cassette).to be_nil
|
379
379
|
end
|
380
380
|
end
|
381
381
|
end
|
@@ -392,7 +392,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
392
392
|
it_behaves_like "request hooks", library_hook_name, :unhandled do
|
393
393
|
undef assert_expected_response
|
394
394
|
def assert_expected_response(response)
|
395
|
-
response.
|
395
|
+
expect(response).to be_nil
|
396
396
|
end
|
397
397
|
|
398
398
|
undef make_request
|
@@ -427,7 +427,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
427
427
|
|
428
428
|
valid.each do |val, response|
|
429
429
|
it "returns the expected response for a #{val.inspect} request" do
|
430
|
-
get_body_string(make_http_request(val)).
|
430
|
+
expect(get_body_string(make_http_request(val))).to eq(response)
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
@@ -480,7 +480,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
480
480
|
if http_allowed
|
481
481
|
|
482
482
|
it 'allows real http requests' do
|
483
|
-
get_body_string(make_http_request(:get, url)).
|
483
|
+
expect(get_body_string(make_http_request(:get, url))).to eq('FOO!')
|
484
484
|
end
|
485
485
|
|
486
486
|
describe 'recording new http requests' do
|
@@ -499,37 +499,37 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
499
499
|
end unless other.include?(:not_disableable)
|
500
500
|
|
501
501
|
it 'records the request uri' do
|
502
|
-
recorded_interaction.request.uri.
|
502
|
+
expect(recorded_interaction.request.uri).to eq(url)
|
503
503
|
end
|
504
504
|
|
505
505
|
it 'records the request method' do
|
506
|
-
recorded_interaction.request.method.
|
506
|
+
expect(recorded_interaction.request.method).to eq(:post)
|
507
507
|
end
|
508
508
|
|
509
509
|
it 'records the request body' do
|
510
|
-
recorded_interaction.request.body.
|
510
|
+
expect(recorded_interaction.request.body).to eq("the body")
|
511
511
|
end
|
512
512
|
|
513
513
|
it 'records the request headers' do
|
514
514
|
headers = downcase_headers(recorded_interaction.request.headers)
|
515
|
-
headers.
|
515
|
+
expect(headers).to include('x-http-foo' => ['bar'])
|
516
516
|
end
|
517
517
|
|
518
518
|
it 'records the response status code' do
|
519
|
-
recorded_interaction.response.status.code.
|
519
|
+
expect(recorded_interaction.response.status.code).to eq(200)
|
520
520
|
end
|
521
521
|
|
522
522
|
it 'records the response status message' do
|
523
|
-
recorded_interaction.response.status.message.strip.
|
523
|
+
expect(recorded_interaction.response.status.message.strip).to eq('OK')
|
524
524
|
end unless other.include?(:status_message_not_exposed)
|
525
525
|
|
526
526
|
it 'records the response body' do
|
527
|
-
recorded_interaction.response.body.
|
527
|
+
expect(recorded_interaction.response.body).to eq('FOO!')
|
528
528
|
end
|
529
529
|
|
530
530
|
it 'records the response headers' do
|
531
531
|
headers = downcase_headers(recorded_interaction.response.headers)
|
532
|
-
headers.
|
532
|
+
expect(headers).to include('content-type' => ["text/html;charset=utf-8"])
|
533
533
|
end
|
534
534
|
end
|
535
535
|
else
|
@@ -556,7 +556,7 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
556
556
|
|
557
557
|
%w[ 127.0.0.1 localhost ].each do |localhost_alias|
|
558
558
|
it "allows requests to #{localhost_alias}" do
|
559
|
-
get_body_string(make_http_request(:get, "http://#{localhost_alias}:#{VCR::SinatraApp.port}/localhost_test")).
|
559
|
+
expect(get_body_string(make_http_request(:get, "http://#{localhost_alias}:#{VCR::SinatraApp.port}/localhost_test"))).to eq(localhost_response)
|
560
560
|
end
|
561
561
|
end
|
562
562
|
|
@@ -574,18 +574,18 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
|
|
574
574
|
|
575
575
|
it 'gets the stubbed responses when requests are made to http://example.com/foo, and does not record them' do
|
576
576
|
VCR.should_receive(:record_http_interaction).never
|
577
|
-
get_body_string(make_http_request(:get, 'http://example.com/foo')).
|
577
|
+
expect(get_body_string(make_http_request(:get, 'http://example.com/foo'))).to match(/example\.com get response \d with path=foo/)
|
578
578
|
end
|
579
579
|
|
580
580
|
it 'rotates through multiple responses for the same request' do
|
581
|
-
get_body_string(make_http_request(:get, 'http://example.com/foo')).
|
582
|
-
get_body_string(make_http_request(:get, 'http://example.com/foo')).
|
581
|
+
expect(get_body_string(make_http_request(:get, 'http://example.com/foo'))).to eq('example.com get response 1 with path=foo')
|
582
|
+
expect(get_body_string(make_http_request(:get, 'http://example.com/foo'))).to eq('example.com get response 2 with path=foo')
|
583
583
|
end unless other.include?(:does_not_support_rotating_responses)
|
584
584
|
|
585
585
|
it "correctly handles stubbing multiple values for the same header" do
|
586
586
|
header = get_header('Set-Cookie', make_http_request(:get, 'http://example.com/two_set_cookie_headers'))
|
587
587
|
header = header.split(', ') if header.respond_to?(:split)
|
588
|
-
header.
|
588
|
+
expect(header).to match_array ['bar=bazz', 'foo=bar']
|
589
589
|
end
|
590
590
|
end
|
591
591
|
end
|