vcr 3.0.3 → 6.2.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.
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 +63 -16
  13. data/lib/vcr/configuration.rb +21 -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 +29 -2
  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,326 +0,0 @@
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
@@ -1,85 +0,0 @@
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
-
@@ -1,178 +0,0 @@
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 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 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 are cassettes' 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 single cassette when there is one cassette' 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 the details about all cassettes when there are a few cassettes' do
82
- VCR.use_cassette('example') do
83
- VCR.use_cassette('sample') do
84
- expect(message).to match(/VCR are currently using the following cassettes:.+sample.yml.+example.yml/m)
85
- end
86
- end
87
- end
88
-
89
- it 'mentions that :new_episodes can be used to record the request' do
90
- VCR.use_cassette('example') do
91
- expect(message).to include('use the :new_episodes record mode')
92
- end
93
- end
94
-
95
- it 'mentions that :once does not allow a cassette to be re-recorded' do
96
- VCR.use_cassette('example', :record => :once) do
97
- expect(message).to include('(:once) does not allow new requests to be recorded')
98
- end
99
- end
100
-
101
- it 'mentions that :none does not allow any recording' do
102
- VCR.use_cassette('example', :record => :none) do
103
- expect(message).to include('(:none) does not allow requests to be recorded')
104
- end
105
- end
106
-
107
- it 'does not mention the :once or :none record modes if using the :new_episodes record mode' do
108
- VCR.use_cassette('example', :record => :new_episodes) do
109
- expect(message).not_to include(':once', ':none')
110
- end
111
- end
112
-
113
- it 'does not mention the :once or :none record modes if using the :new_episodes record mode at least in one cassette' do
114
- VCR.use_cassette('example', :record => :new_episodes) do
115
- VCR.use_cassette('sample') do
116
- expect(message).not_to include('current record mode (:once)', 'current record mode (:none)')
117
- end
118
- end
119
- end
120
-
121
- it 'mentions :allow_playback_repeats if the cassette has a used matching interaction' do
122
- VCR.use_cassette('example') do |cassette|
123
- expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?)
124
- allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(true)
125
- expect(message).to include('allow_playback_repeats')
126
- end
127
- end
128
-
129
- it 'does not mention :allow_playback_repeats if the cassette does not have a used matching interaction' do
130
- VCR.use_cassette('example') do |cassette|
131
- expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?)
132
- allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(false)
133
- expect(message).not_to include('allow_playback_repeats')
134
- end
135
- end
136
-
137
- it 'does not mention using a different :match_requests_on option when there are no remaining unused interactions' 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(0)
141
- expect(message).not_to include('match_requests_on cassette option')
142
- end
143
- end
144
-
145
- it 'mentions using a different :match_requests_on option when there are some remaining unused interactions' 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(1)
149
- expect(message).to include('match_requests_on cassette option')
150
- end
151
- end
152
-
153
- it 'uses the singular (HTTP interaction) when there is only 1 left' do
154
- VCR.use_cassette('example') do |cassette|
155
- expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
156
- allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(1)
157
- expect(message).to include('1 HTTP interaction ')
158
- end
159
- end
160
-
161
- it 'uses the plural (HTTP interactions) when there is more than 1 left' do
162
- VCR.use_cassette('example') do |cassette|
163
- expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
164
- allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(2)
165
- expect(message).to include('2 HTTP interactions ')
166
- end
167
- end
168
-
169
- it 'mentions the debug logging configuration option' do
170
- VCR.use_cassette('example', :record => :new_episodes) do
171
- expect(message).to include('debug_logger')
172
- end
173
- end
174
- end
175
- end
176
- end
177
- end
178
-
@@ -1,86 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe VCR::Net::HTTPResponse do
4
- def self.it_allows_the_body_to_be_read(expected_regex)
5
- it 'allows the body to be read using #body' do
6
- expect(response.body.to_s).to match expected_regex
7
- end
8
-
9
- it 'allows the body to be read using #read_body' do
10
- expect(response.read_body.to_s).to match expected_regex
11
- end
12
-
13
- it 'allows the body to be read using #read_body with a block' do
14
- yielded_body = ''
15
- response { |r| r.read_body { |s| yielded_body << s.to_s } }
16
- expect(yielded_body).to match expected_regex
17
- end
18
-
19
- it 'allows the body to be read by passing a destination string to #read_body' do
20
- dest = ''
21
- ret_val = response { |r| r.read_body(dest) }.body
22
- expect(dest.to_s).to match expected_regex
23
- expect(ret_val.to_s).to eq(dest)
24
- end
25
-
26
- it 'raises an ArgumentError if both a destination string and a block is given to #read_body' do
27
- dest = ''
28
- expect { response { |r| r.read_body(dest) { |s| } } }.to raise_error(ArgumentError, 'both arg and block given for HTTP method')
29
- end
30
-
31
- it 'raises an IOError when #read_body is called twice with a block' do
32
- response { |r| r.read_body { |s| } }
33
- expect { response { |r| r.read_body { |s| } } }.to raise_error(IOError, /read_body called twice/)
34
- end
35
-
36
- it 'raises an IOError when #read_body is called twice with a destination string' do
37
- dest = ''
38
- response { |r| r.read_body(dest) }
39
- expect { response { |r| r.read_body(dest) } }.to raise_error(IOError, /read_body called twice/)
40
- end
41
- end
42
-
43
- { :get => /GET to root/, :head => /\A\z/ }.each do |http_verb, expected_body_regex|
44
- context "for a #{http_verb.to_s.upcase} request" do
45
- let(:http_verb_method) { :"request_#{http_verb}" }
46
-
47
- def response(&block)
48
- if defined?(@response) && block
49
- block.call(@response)
50
- return @response
51
- end
52
-
53
- @response ||= begin
54
- http = Net::HTTP.new('localhost', VCR::SinatraApp.port)
55
- res = http.send(http_verb_method, '/', &block)
56
- expect(res).not_to be_a(VCR::Net::HTTPResponse)
57
- expect(res).not_to be_a(::Net::WebMockHTTPResponse)
58
- res
59
- end
60
- end
61
-
62
- context 'when the body has not already been read' do
63
- it_allows_the_body_to_be_read(expected_body_regex)
64
- end
65
-
66
- context 'when the body has already been read using #read_body and a dest string' do
67
- before(:each) do
68
- dest = ''
69
- response { |res| res.read_body(dest) }
70
- response.extend VCR::Net::HTTPResponse
71
- end
72
-
73
- it_allows_the_body_to_be_read(expected_body_regex)
74
- end
75
-
76
- context 'when the body has already been read using #body' do
77
- before(:each) do
78
- response.body
79
- response.extend VCR::Net::HTTPResponse
80
- end
81
-
82
- it_allows_the_body_to_be_read(expected_body_regex)
83
- end
84
- end
85
- end
86
- end