mustwin-vcr 2.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/features/about_these_examples.md +18 -0
  3. data/features/cassettes/allow_unused_http_interactions.feature +100 -0
  4. data/features/cassettes/automatic_re_recording.feature +72 -0
  5. data/features/cassettes/decompress.feature +74 -0
  6. data/features/cassettes/dynamic_erb.feature +100 -0
  7. data/features/cassettes/exclusive.feature +126 -0
  8. data/features/cassettes/format.feature +323 -0
  9. data/features/cassettes/freezing_time.feature +68 -0
  10. data/features/cassettes/naming.feature +28 -0
  11. data/features/cassettes/no_cassette.feature +152 -0
  12. data/features/cassettes/update_content_length_header.feature +112 -0
  13. data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
  14. data/features/configuration/cassette_library_dir.feature +31 -0
  15. data/features/configuration/debug_logging.feature +59 -0
  16. data/features/configuration/default_cassette_options.feature +100 -0
  17. data/features/configuration/filter_sensitive_data.feature +153 -0
  18. data/features/configuration/hook_into.feature +172 -0
  19. data/features/configuration/ignore_request.feature +192 -0
  20. data/features/configuration/preserve_exact_body_bytes.feature +108 -0
  21. data/features/configuration/query_parser.feature +84 -0
  22. data/features/configuration/uri_parser.feature +89 -0
  23. data/features/getting_started.md +82 -0
  24. data/features/hooks/after_http_request.feature +58 -0
  25. data/features/hooks/around_http_request.feature +57 -0
  26. data/features/hooks/before_http_request.feature +63 -0
  27. data/features/hooks/before_playback.feature +184 -0
  28. data/features/hooks/before_record.feature +172 -0
  29. data/features/http_libraries/em_http_request.feature +250 -0
  30. data/features/http_libraries/net_http.feature +179 -0
  31. data/features/middleware/faraday.feature +56 -0
  32. data/features/middleware/rack.feature +92 -0
  33. data/features/record_modes/all.feature +82 -0
  34. data/features/record_modes/new_episodes.feature +79 -0
  35. data/features/record_modes/none.feature +72 -0
  36. data/features/record_modes/once.feature +95 -0
  37. data/features/request_matching/README.md +30 -0
  38. data/features/request_matching/body.feature +91 -0
  39. data/features/request_matching/body_as_json.feature +90 -0
  40. data/features/request_matching/custom_matcher.feature +135 -0
  41. data/features/request_matching/headers.feature +85 -0
  42. data/features/request_matching/host.feature +95 -0
  43. data/features/request_matching/identical_request_sequence.feature +89 -0
  44. data/features/request_matching/method.feature +96 -0
  45. data/features/request_matching/path.feature +96 -0
  46. data/features/request_matching/playback_repeats.feature +98 -0
  47. data/features/request_matching/query.feature +97 -0
  48. data/features/request_matching/uri.feature +94 -0
  49. data/features/request_matching/uri_without_param.feature +101 -0
  50. data/features/step_definitions/cli_steps.rb +193 -0
  51. data/features/support/env.rb +44 -0
  52. data/features/support/http_lib_filters.rb +53 -0
  53. data/features/test_frameworks/cucumber.feature +211 -0
  54. data/features/test_frameworks/rspec_macro.feature +81 -0
  55. data/features/test_frameworks/rspec_metadata.feature +150 -0
  56. data/features/test_frameworks/test_unit.feature +49 -0
  57. data/lib/vcr.rb +347 -0
  58. data/lib/vcr/cassette.rb +291 -0
  59. data/lib/vcr/cassette/erb_renderer.rb +55 -0
  60. data/lib/vcr/cassette/http_interaction_list.rb +108 -0
  61. data/lib/vcr/cassette/migrator.rb +118 -0
  62. data/lib/vcr/cassette/persisters.rb +42 -0
  63. data/lib/vcr/cassette/persisters/file_system.rb +64 -0
  64. data/lib/vcr/cassette/serializers.rb +57 -0
  65. data/lib/vcr/cassette/serializers/json.rb +48 -0
  66. data/lib/vcr/cassette/serializers/psych.rb +48 -0
  67. data/lib/vcr/cassette/serializers/syck.rb +61 -0
  68. data/lib/vcr/cassette/serializers/yaml.rb +50 -0
  69. data/lib/vcr/configuration.rb +555 -0
  70. data/lib/vcr/deprecations.rb +109 -0
  71. data/lib/vcr/errors.rb +266 -0
  72. data/lib/vcr/extensions/net_http_response.rb +36 -0
  73. data/lib/vcr/library_hooks.rb +18 -0
  74. data/lib/vcr/library_hooks/excon.rb +27 -0
  75. data/lib/vcr/library_hooks/fakeweb.rb +196 -0
  76. data/lib/vcr/library_hooks/faraday.rb +51 -0
  77. data/lib/vcr/library_hooks/typhoeus.rb +120 -0
  78. data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
  79. data/lib/vcr/library_hooks/webmock.rb +164 -0
  80. data/lib/vcr/middleware/excon.rb +221 -0
  81. data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
  82. data/lib/vcr/middleware/faraday.rb +118 -0
  83. data/lib/vcr/middleware/rack.rb +79 -0
  84. data/lib/vcr/request_handler.rb +114 -0
  85. data/lib/vcr/request_ignorer.rb +43 -0
  86. data/lib/vcr/request_matcher_registry.rb +149 -0
  87. data/lib/vcr/structs.rb +578 -0
  88. data/lib/vcr/tasks/vcr.rake +9 -0
  89. data/lib/vcr/test_frameworks/cucumber.rb +64 -0
  90. data/lib/vcr/test_frameworks/rspec.rb +47 -0
  91. data/lib/vcr/util/hooks.rb +61 -0
  92. data/lib/vcr/util/internet_connection.rb +43 -0
  93. data/lib/vcr/util/logger.rb +59 -0
  94. data/lib/vcr/util/variable_args_block_caller.rb +13 -0
  95. data/lib/vcr/util/version_checker.rb +48 -0
  96. data/lib/vcr/version.rb +34 -0
  97. data/spec/acceptance/threading_spec.rb +34 -0
  98. data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
  99. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  100. data/spec/fixtures/cassette_spec/example.yml +111 -0
  101. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
  102. data/spec/fixtures/fake_example_responses.yml +110 -0
  103. data/spec/fixtures/match_requests_on.yml +187 -0
  104. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
  105. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
  106. data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
  107. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
  108. data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
  109. data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
  110. data/spec/lib/vcr/cassette_spec.rb +618 -0
  111. data/spec/lib/vcr/configuration_spec.rb +326 -0
  112. data/spec/lib/vcr/deprecations_spec.rb +85 -0
  113. data/spec/lib/vcr/errors_spec.rb +162 -0
  114. data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
  115. data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
  116. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
  117. data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
  118. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
  119. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
  120. data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
  121. data/spec/lib/vcr/library_hooks_spec.rb +51 -0
  122. data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
  123. data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
  124. data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
  125. data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
  126. data/spec/lib/vcr/structs_spec.rb +732 -0
  127. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
  128. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
  129. data/spec/lib/vcr/util/hooks_spec.rb +158 -0
  130. data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
  131. data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
  132. data/spec/lib/vcr/version_spec.rb +27 -0
  133. data/spec/lib/vcr_spec.rb +349 -0
  134. data/spec/monkey_patches.rb +182 -0
  135. data/spec/spec_helper.rb +62 -0
  136. data/spec/support/configuration_stubbing.rb +8 -0
  137. data/spec/support/cucumber_helpers.rb +35 -0
  138. data/spec/support/fixnum_extension.rb +10 -0
  139. data/spec/support/http_library_adapters.rb +289 -0
  140. data/spec/support/limited_uri.rb +21 -0
  141. data/spec/support/ruby_interpreter.rb +7 -0
  142. data/spec/support/shared_example_groups/excon.rb +63 -0
  143. data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
  144. data/spec/support/shared_example_groups/request_hooks.rb +59 -0
  145. data/spec/support/sinatra_app.rb +86 -0
  146. data/spec/support/vcr_localhost_server.rb +76 -0
  147. data/spec/support/vcr_stub_helpers.rb +17 -0
  148. metadata +677 -0
@@ -0,0 +1,326 @@
1
+ require 'spec_helper'
2
+
3
+ describe VCR::Configuration do
4
+ describe '#cassette_library_dir=' do
5
+ let(:tmp_dir) { VCR::SPEC_ROOT + '/../tmp/cassette_library_dir/new_dir' }
6
+ after(:each) { FileUtils.rm_rf tmp_dir }
7
+
8
+ it 'creates the directory if it does not exist' do
9
+ expect { subject.cassette_library_dir = tmp_dir }.to change { File.exist?(tmp_dir) }.from(false).to(true)
10
+ end
11
+
12
+ it 'does not raise an error if given nil' do
13
+ expect { subject.cassette_library_dir = nil }.to_not raise_error
14
+ end
15
+
16
+ it 'resolves the given directory to an absolute path, so VCR continues to work even if the current directory changes' do
17
+ relative_dir = 'tmp/cassette_library_dir/new_dir'
18
+ subject.cassette_library_dir = relative_dir
19
+ absolute_dir = File.join(VCR::SPEC_ROOT.sub(/\/spec\z/, ''), relative_dir)
20
+ expect(subject.cassette_library_dir).to eq(absolute_dir)
21
+ end
22
+ end
23
+
24
+ describe '#default_cassette_options' do
25
+ it 'has a hash with some defaults' do
26
+ expect(subject.default_cassette_options).to eq({
27
+ :match_requests_on => VCR::RequestMatcherRegistry::DEFAULT_MATCHERS,
28
+ :allow_unused_http_interactions => true,
29
+ :record => :once,
30
+ :serialize_with => :yaml,
31
+ :persist_with => :file_system
32
+ })
33
+ end
34
+
35
+ it "returns #{VCR::RequestMatcherRegistry::DEFAULT_MATCHERS.inspect} for :match_requests_on when other defaults have been set" do
36
+ subject.default_cassette_options = { :record => :none }
37
+ expect(subject.default_cassette_options).to include(:match_requests_on => VCR::RequestMatcherRegistry::DEFAULT_MATCHERS)
38
+ end
39
+
40
+ it "returns :once for :record when other defaults have been set" do
41
+ subject.default_cassette_options = { :erb => :true }
42
+ expect(subject.default_cassette_options).to include(:record => :once)
43
+ end
44
+
45
+ it "allows defaults to be overriden" do
46
+ subject.default_cassette_options = { :record => :all }
47
+ expect(subject.default_cassette_options).to include(:record => :all)
48
+ end
49
+
50
+ it "allows other keys to be set" do
51
+ subject.default_cassette_options = { :re_record_interval => 10 }
52
+ expect(subject.default_cassette_options).to include(:re_record_interval => 10)
53
+ end
54
+ end
55
+
56
+ describe '#register_request_matcher' do
57
+ it 'registers the given request matcher' do
58
+ expect {
59
+ VCR.request_matchers[:custom]
60
+ }.to raise_error(VCR::UnregisteredMatcherError)
61
+
62
+ matcher_run = false
63
+ subject.register_request_matcher(:custom) { |r1, r2| matcher_run = true }
64
+ VCR.request_matchers[:custom].matches?(:r1, :r2)
65
+ expect(matcher_run).to be true
66
+ end
67
+ end
68
+
69
+ describe '#hook_into' do
70
+ it 'requires the named library hook' do
71
+ expect(subject).to receive(:require).with("vcr/library_hooks/fakeweb")
72
+ expect(subject).to receive(:require).with("vcr/library_hooks/excon")
73
+ subject.hook_into :fakeweb, :excon
74
+ end
75
+
76
+ it 'raises an error for unsupported stubbing libraries' do
77
+ expect {
78
+ subject.hook_into :unsupported_library
79
+ }.to raise_error(ArgumentError, /unsupported_library is not a supported VCR HTTP library hook/i)
80
+ end
81
+
82
+ it 'invokes the after_library_hooks_loaded hooks' do
83
+ called = false
84
+ subject.after_library_hooks_loaded { called = true }
85
+ subject.hook_into :fakeweb
86
+ expect(called).to be true
87
+ end
88
+ end
89
+
90
+ describe '#ignore_hosts' do
91
+ it 'delegates to the current request_ignorer instance' do
92
+ expect(VCR.request_ignorer).to receive(:ignore_hosts).with('example.com', 'example.net')
93
+ subject.ignore_hosts 'example.com', 'example.net'
94
+ end
95
+ end
96
+
97
+ describe '#ignore_localhost=' do
98
+ it 'delegates to the current request_ignorer instance' do
99
+ expect(VCR.request_ignorer).to receive(:ignore_localhost=).with(true)
100
+ subject.ignore_localhost = true
101
+ end
102
+ end
103
+
104
+ describe '#ignore_request' do
105
+ let(:uri){ URI('http://foo.com') }
106
+
107
+ it 'registers the given block with the request ignorer' do
108
+ block_called = false
109
+ subject.ignore_request { |r| block_called = true }
110
+ VCR.request_ignorer.ignore?(double(:parsed_uri => uri))
111
+ expect(block_called).to be true
112
+ end
113
+ end
114
+
115
+ describe '#allow_http_connections_when_no_cassette=' do
116
+ [true, false].each do |val|
117
+ it "sets the allow_http_connections_when_no_cassette to #{val} when set to #{val}" do
118
+ subject.allow_http_connections_when_no_cassette = val
119
+ expect(subject.allow_http_connections_when_no_cassette?).to eq(val)
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "request/configuration interactions", :with_monkey_patches => :fakeweb do
125
+ specify 'the request on the yielded interaction is not typed even though the request given to before_http_request is' do
126
+ before_record_req = before_request_req = nil
127
+ VCR.configure do |c|
128
+ c.before_http_request { |r| before_request_req = r }
129
+ c.before_record { |i| before_record_req = i.request }
130
+ end
131
+
132
+ VCR.use_cassette("example") do
133
+ ::Net::HTTP.get_response(URI("http://localhost:#{VCR::SinatraApp.port}/foo"))
134
+ end
135
+
136
+ expect(before_record_req).not_to respond_to(:type)
137
+ expect(before_request_req).to respond_to(:type)
138
+ end unless (RUBY_VERSION =~ /^1\.8/ || RUBY_INTERPRETER == :jruby)
139
+
140
+ specify 'the filter_sensitive_data option works even when it modifies the URL in a way that makes it an invalid URI' do
141
+ VCR.configure do |c|
142
+ c.filter_sensitive_data('<HOST>') { 'localhost' }
143
+ end
144
+
145
+ 2.times do
146
+ VCR.use_cassette("example") do
147
+ ::Net::HTTP.get_response(URI("http://localhost:#{VCR::SinatraApp.port}/foo"))
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ [:before_record, :before_playback].each do |hook_type|
154
+ describe "##{hook_type}" do
155
+ it 'sets up a tag filter' do
156
+ called = false
157
+ VCR.configuration.send(hook_type, :my_tag) { called = true }
158
+ VCR.configuration.invoke_hook(hook_type, double, double(:tags => []))
159
+ expect(called).to be false
160
+ VCR.configuration.invoke_hook(hook_type, double, double(:tags => [:my_tag]))
161
+ expect(called).to be true
162
+ end
163
+ end
164
+ end
165
+
166
+ %w[ filter_sensitive_data define_cassette_placeholder ].each do |method|
167
+ describe "##{method}" do
168
+ let(:interaction) { double('interaction').as_null_object }
169
+ before(:each) { allow(interaction).to receive(:filter!) }
170
+
171
+ it 'adds a before_record hook that replaces the string returned by the block with the given string' do
172
+ subject.send(method, 'foo', &lambda { 'bar' })
173
+ expect(interaction).to receive(:filter!).with('bar', 'foo')
174
+ subject.invoke_hook(:before_record, interaction, double.as_null_object)
175
+ end
176
+
177
+ it 'adds a before_playback hook that replaces the given string with the string returned by the block' do
178
+ subject.send(method, 'foo', &lambda { 'bar' })
179
+ expect(interaction).to receive(:filter!).with('foo', 'bar')
180
+ subject.invoke_hook(:before_playback, interaction, double.as_null_object)
181
+ end
182
+
183
+ it 'tags the before_record hook when given a tag' do
184
+ expect(subject).to receive(:before_record).with(:my_tag)
185
+ subject.send(method, 'foo', :my_tag) { 'bar' }
186
+ end
187
+
188
+ it 'tags the before_playback hook when given a tag' do
189
+ expect(subject).to receive(:before_playback).with(:my_tag)
190
+ subject.send(method, 'foo', :my_tag) { 'bar' }
191
+ end
192
+
193
+ it 'yields the interaction to the block for the before_record hook' do
194
+ yielded_interaction = nil
195
+ subject.send(method, 'foo', &lambda { |i| yielded_interaction = i; 'bar' })
196
+ subject.invoke_hook(:before_record, interaction, double.as_null_object)
197
+ expect(yielded_interaction).to equal(interaction)
198
+ end
199
+
200
+ it 'yields the interaction to the block for the before_playback hook' do
201
+ yielded_interaction = nil
202
+ subject.send(method, 'foo', &lambda { |i| yielded_interaction = i; 'bar' })
203
+ subject.invoke_hook(:before_playback, interaction, double.as_null_object)
204
+ expect(yielded_interaction).to equal(interaction)
205
+ end
206
+ end
207
+ end
208
+
209
+ describe "#after_http_request" do
210
+ let(:raw_request) { VCR::Request.new }
211
+ let(:response) { VCR::Response.new }
212
+
213
+ def request(type)
214
+ VCR::Request::Typed.new(raw_request, type)
215
+ end
216
+
217
+ it 'handles symbol request predicate filters properly' do
218
+ yielded = false
219
+ subject.after_http_request(:stubbed_by_vcr?) { |req| yielded = true }
220
+ subject.invoke_hook(:after_http_request, request(:stubbed_by_vcr), response)
221
+ expect(yielded).to be true
222
+
223
+ yielded = false
224
+ subject.invoke_hook(:after_http_request, request(:ignored), response)
225
+ expect(yielded).to be false
226
+ end
227
+ end
228
+
229
+ describe "#around_http_request, when called on ruby 1.8" do
230
+ it 'raises an error since fibers are not available' do
231
+ expect {
232
+ subject.around_http_request { }
233
+ }.to raise_error(/requires fibers, which are not available/)
234
+ end
235
+ end if RUBY_VERSION < '1.9'
236
+
237
+ describe "#cassette_serializers" do
238
+ let(:custom_serializer) { double }
239
+ it 'allows a custom serializer to be registered' do
240
+ expect { subject.cassette_serializers[:custom] }.to raise_error(ArgumentError)
241
+ subject.cassette_serializers[:custom] = custom_serializer
242
+ expect(subject.cassette_serializers[:custom]).to be(custom_serializer)
243
+ end
244
+ end
245
+
246
+ describe "#cassette_persisters" do
247
+ let(:custom_persister) { double }
248
+ it 'allows a custom persister to be registered' do
249
+ expect { subject.cassette_persisters[:custom] }.to raise_error(ArgumentError)
250
+ subject.cassette_persisters[:custom] = custom_persister
251
+ expect(subject.cassette_persisters[:custom]).to be(custom_persister)
252
+ end
253
+ end
254
+
255
+ describe "#uri_parser=" do
256
+ let(:custom_parser) { double }
257
+ it 'allows a custom uri parser to be set' do
258
+ subject.uri_parser = custom_parser
259
+ expect(subject.uri_parser).to eq(custom_parser)
260
+ end
261
+
262
+ it "uses Ruby's standard library `URI` as a default" do
263
+ expect(subject.uri_parser).to eq(URI)
264
+ end
265
+ end
266
+
267
+ describe "#preserve_exact_body_bytes_for?" do
268
+ def message_for(body)
269
+ double(:body => body)
270
+ end
271
+
272
+ context "default hook" do
273
+ it "returns false when there is no current cassette" do
274
+ expect(subject.preserve_exact_body_bytes_for?(message_for "string")).to be false
275
+ end
276
+
277
+ it "returns false when the current cassette has been created without the :preserve_exact_body_bytes option" do
278
+ VCR.insert_cassette('foo')
279
+ expect(subject.preserve_exact_body_bytes_for?(message_for "string")).to be false
280
+ end
281
+
282
+ it 'returns true when the current cassette has been created with the :preserve_exact_body_bytes option' do
283
+ VCR.insert_cassette('foo', :preserve_exact_body_bytes => true)
284
+ expect(subject.preserve_exact_body_bytes_for?(message_for "string")).to be true
285
+ end
286
+ end
287
+
288
+ it "returns true when the configured block returns true" do
289
+ subject.preserve_exact_body_bytes { |msg| msg.body == "a" }
290
+ expect(subject.preserve_exact_body_bytes_for?(message_for "a")).to be true
291
+ expect(subject.preserve_exact_body_bytes_for?(message_for "b")).to be false
292
+ end
293
+
294
+ it "returns true when any of the registered blocks returns true" do
295
+ called_hooks = []
296
+ subject.preserve_exact_body_bytes { called_hooks << :hook_1; false }
297
+ subject.preserve_exact_body_bytes { called_hooks << :hook_2; true }
298
+ expect(subject.preserve_exact_body_bytes_for?(message_for "a")).to be true
299
+ expect(called_hooks).to eq([:hook_1, :hook_2])
300
+ end
301
+
302
+ it "invokes the configured hook with the http message and the current cassette" do
303
+ VCR.use_cassette('example') do |cassette|
304
+ expect(cassette).to be_a(VCR::Cassette)
305
+ message = double(:message)
306
+
307
+ yielded_objects = nil
308
+ subject.preserve_exact_body_bytes { |a, b| yielded_objects = [a, b] }
309
+ subject.preserve_exact_body_bytes_for?(message)
310
+ expect(yielded_objects).to eq([message, cassette])
311
+ end
312
+ end
313
+ end
314
+
315
+ describe "#configure_rspec_metadata!" do
316
+ it "only configures the underlying metadata once, no matter how many times it is called" do
317
+ expect(VCR::RSpec::Metadata).to receive(:configure!).once
318
+ VCR.configure do |c|
319
+ c.configure_rspec_metadata!
320
+ end
321
+ VCR.configure do |c|
322
+ c.configure_rspec_metadata!
323
+ end
324
+ end
325
+ end
326
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe VCR, 'deprecations', :disable_warnings do
4
+ describe ".config" do
5
+ it 'delegates to VCR.configure' do
6
+ expect(VCR).to receive(:configure)
7
+ VCR.config { }
8
+ end
9
+
10
+ it 'yields the configuration object' do
11
+ config_object = nil
12
+ VCR.config { |c| config_object = c }
13
+ expect(config_object).to be(VCR.configuration)
14
+ end
15
+
16
+ it 'prints a deprecation warning' do
17
+ expect(VCR).to receive(:warn).with(/VCR.config.*deprecated/i)
18
+
19
+ VCR.config { }
20
+ end
21
+ end
22
+
23
+ describe "Config" do
24
+ it 'returns the same object referenced by VCR.configuration' do
25
+ expect(VCR::Config).to be(VCR.configuration)
26
+ end
27
+
28
+ it 'prints a deprecation warning' do
29
+ expect(VCR).to receive(:warn).with(/VCR::Config.*deprecated/i)
30
+
31
+ VCR::Config
32
+ end
33
+
34
+ it 'preserves the normal undefined constant behavior' do
35
+ expect {
36
+ VCR::SomeUndefinedConstant
37
+ }.to raise_error(NameError)
38
+ end
39
+ end
40
+
41
+ describe "Cassette::MissingERBVariableError" do
42
+ it 'returns VCR::Errors::MissingERBVariableError' do
43
+ expect(VCR::Cassette::MissingERBVariableError).to be(VCR::Errors::MissingERBVariableError)
44
+ end
45
+
46
+ it 'prints a deprecation warning' do
47
+ expect(VCR::Cassette).to receive(:warn).with(/VCR::Cassette::MissingERBVariableError.*deprecated/i)
48
+
49
+ VCR::Cassette::MissingERBVariableError
50
+ end
51
+
52
+ it 'preserves the normal undefined constant behavior' do
53
+ expect {
54
+ VCR::Cassette::SomeUndefinedConstant
55
+ }.to raise_error(NameError)
56
+ end
57
+ end
58
+
59
+ describe "VCR.configure { |c| c.stub_with ... }" do
60
+ it 'delegates to #hook_into' do
61
+ expect(VCR.configuration).to receive(:hook_into).with(:fakeweb, :excon)
62
+ VCR.configure { |c| c.stub_with :fakeweb, :excon }
63
+ end
64
+
65
+ it 'prints a deprecation warning' do
66
+ expect(VCR.configuration).to receive(:warn).with(/stub_with.*deprecated/i)
67
+ VCR.configure { |c| c.stub_with :fakeweb, :excon }
68
+ end
69
+ end
70
+
71
+ describe "VCR::Middleware::Faraday" do
72
+ it 'prints a deprecation warning when passed a block' do
73
+ expect(Kernel).to receive(:warn).with(/Passing a block .* is deprecated/)
74
+ VCR::Middleware::Faraday.new(double) { }
75
+ end
76
+ end
77
+
78
+ describe "VCR::RSpec::Macros" do
79
+ it 'prints a deprecation warning' do
80
+ expect(Kernel).to receive(:warn).with(/VCR::RSpec::Macros is deprecated/)
81
+ Class.new.extend(VCR::RSpec::Macros)
82
+ end
83
+ end
84
+ end
85
+
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ module VCR
4
+ module Errors
5
+ describe UnhandledHTTPRequestError do
6
+ def message_for(request_values = {})
7
+ described_class.new(request_with request_values).message
8
+ end
9
+ alias message message_for
10
+
11
+ def request_with(values)
12
+ VCR::Request.new.tap do |request|
13
+ values.each do |name, value|
14
+ request.send("#{name}=", value)
15
+ end
16
+ end
17
+ end
18
+
19
+ it 'identifies the request by method and URI' do
20
+ expect(message_for(:method => :post, :uri => 'http://foo.com/')).to include(
21
+ 'POST http://foo.com/'
22
+ )
23
+ end
24
+
25
+ context 'when there is no current cassette' do
26
+ it 'identifies the request by its body when the default_cassette_options include the body in the match_requests_on option' do
27
+ VCR.configuration.default_cassette_options[:match_requests_on] = [:body]
28
+
29
+ expect(message_for(:body => 'param=val1')).to include(
30
+ "Body: param=val1"
31
+ )
32
+ end
33
+
34
+ it 'mentions that there is no current cassette' do
35
+ expect(message).to include('There is currently no cassette in use.')
36
+ end
37
+
38
+ it 'mentions that the request can be recorded by inserting a cassette' do
39
+ expect(message).to match(/record this request and play it back.*VCR.use_cassette/m)
40
+ end
41
+
42
+ it 'mentions the allow_http_connections_when_no_cassette option' do
43
+ expect(message).to include('allow_http_connections_when_no_cassette')
44
+ end
45
+
46
+ it 'mentions that the request can be ignored' do
47
+ expect(message).to include('set an `ignore_request` callback')
48
+ end
49
+
50
+ it 'does not double-insert the asterisks for the bullet points' do
51
+ expect(message).not_to match(/\s+\*\s+\*/)
52
+ end
53
+
54
+ it 'mentions the debug logging configuration option' do
55
+ expect(message).to include('debug_logger')
56
+ end
57
+ end
58
+
59
+ context 'when there is a current cassette' do
60
+ it 'identifies the request by its body when the match_requests_on option includes the body' do
61
+ VCR.use_cassette('example', :match_requests_on => [:body]) do
62
+ expect(message_for(:body => 'param=val1')).to include(
63
+ "Body: param=val1"
64
+ )
65
+ end
66
+ end
67
+
68
+ it 'does not identify the request by its body when the cassette match_requests_on option does not include the body but the default_cassette_options do' do
69
+ VCR.configuration.default_cassette_options[:match_requests_on] = [:body]
70
+ VCR.use_cassette('example', :match_requests_on => [:uri]) do
71
+ expect(message_for(:body => 'param=val1')).to_not match(/body/i)
72
+ end
73
+ end
74
+
75
+ it 'mentions the details about the current casette' do
76
+ VCR.use_cassette('example') do
77
+ expect(message).to match(/VCR is currently using the following cassette:.+example.yml/m)
78
+ end
79
+ end
80
+
81
+ it 'mentions that :new_episodes can be used to record the request' do
82
+ VCR.use_cassette('example') do
83
+ expect(message).to include('use the :new_episodes record mode')
84
+ end
85
+ end
86
+
87
+ it 'mentions that :once does not allow a cassette to be re-recorded' do
88
+ VCR.use_cassette('example', :record => :once) do
89
+ expect(message).to include('(:once) does not allow new requests to be recorded')
90
+ end
91
+ end
92
+
93
+ it 'mentions that :none does not allow any recording' do
94
+ VCR.use_cassette('example', :record => :none) do
95
+ expect(message).to include('(:none) does not allow requests to be recorded')
96
+ end
97
+ end
98
+
99
+ it 'does not mention the :once or :none record modes if using the :new_episodes record mode' do
100
+ VCR.use_cassette('example', :record => :new_episodes) do
101
+ expect(message).not_to include(':once', ':none')
102
+ end
103
+ end
104
+
105
+ it 'mentions :allow_playback_repeats if the current cassette has a used matching interaction' do
106
+ VCR.use_cassette('example') do |cassette|
107
+ expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?)
108
+ allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(true)
109
+ expect(message).to include('allow_playback_repeats')
110
+ end
111
+ end
112
+
113
+ it 'does not mention :allow_playback_repeats if the current cassette does not have a used matching interaction' do
114
+ VCR.use_cassette('example') do |cassette|
115
+ expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?)
116
+ allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(false)
117
+ expect(message).not_to include('allow_playback_repeats')
118
+ end
119
+ end
120
+
121
+ it 'does not mention using a different :match_requests_on option when there are no remaining unused interactions' do
122
+ VCR.use_cassette('example') do |cassette|
123
+ expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
124
+ allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(0)
125
+ expect(message).not_to include('match_requests_on cassette option')
126
+ end
127
+ end
128
+
129
+ it 'mentions using a different :match_requests_on option when there are some remaining unused interactions' do
130
+ VCR.use_cassette('example') do |cassette|
131
+ expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
132
+ allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(1)
133
+ expect(message).to include('match_requests_on cassette option')
134
+ end
135
+ end
136
+
137
+ it 'uses the singular (HTTP interaction) when there is only 1 left' do
138
+ VCR.use_cassette('example') do |cassette|
139
+ expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
140
+ allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(1)
141
+ expect(message).to include('1 HTTP interaction ')
142
+ end
143
+ end
144
+
145
+ it 'uses the plural (HTTP interactions) when there is more than 1 left' do
146
+ VCR.use_cassette('example') do |cassette|
147
+ expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
148
+ allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(2)
149
+ expect(message).to include('2 HTTP interactions ')
150
+ end
151
+ end
152
+
153
+ it 'mentions the debug logging configuration option' do
154
+ VCR.use_cassette('example', :record => :new_episodes) do
155
+ expect(message).to include('debug_logger')
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+