vcr 1.6.0 → 1.7.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 (82) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +5 -0
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +29 -2
  5. data/Gemfile +3 -3
  6. data/README.md +55 -11
  7. data/Rakefile +45 -4
  8. data/features/.nav +6 -0
  9. data/features/{README.md → about_the_cucumber_features.md} +1 -1
  10. data/features/cassettes/update_content_length_header.feature +106 -0
  11. data/features/configuration/default_cassette_options.feature +20 -2
  12. data/features/configuration/filter_sensitive_data.feature +154 -0
  13. data/features/getting_started.md +67 -0
  14. data/features/record_modes/all.feature +4 -2
  15. data/features/record_modes/new_episodes.feature +8 -2
  16. data/features/record_modes/none.feature +4 -2
  17. data/features/record_modes/once.feature +92 -0
  18. data/features/step_definitions/cli_steps.rb +18 -0
  19. data/lib/vcr.rb +13 -6
  20. data/lib/vcr/cassette.rb +36 -15
  21. data/lib/vcr/config.rb +14 -2
  22. data/lib/vcr/deprecations/cassette.rb +29 -0
  23. data/lib/vcr/deprecations/config.rb +18 -0
  24. data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +9 -0
  25. data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +11 -0
  26. data/lib/vcr/http_stubbing_adapters/common.rb +1 -1
  27. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +2 -7
  28. data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +1 -1
  29. data/lib/vcr/middleware/common.rb +3 -5
  30. data/lib/vcr/rspec.rb +1 -38
  31. data/lib/vcr/structs/http_interaction.rb +29 -0
  32. data/lib/vcr/structs/request.rb +6 -0
  33. data/lib/vcr/structs/response.rb +4 -0
  34. data/lib/vcr/{cucumber_tags.rb → test_frameworks/cucumber.rb} +10 -2
  35. data/lib/vcr/test_frameworks/rspec.rb +37 -0
  36. data/lib/vcr/util/basic_object.rb +32 -28
  37. data/lib/vcr/{hooks.rb → util/hooks.rb} +3 -6
  38. data/lib/vcr/util/internet_connection.rb +1 -1
  39. data/lib/vcr/util/ping.rb +21 -17
  40. data/lib/vcr/util/variable_args_block_caller.rb +12 -0
  41. data/lib/vcr/util/yaml.rb +11 -0
  42. data/lib/vcr/version.rb +1 -1
  43. data/script/FullBuildRakeFile +7 -0
  44. data/spec/monkey_patches.rb +0 -7
  45. data/spec/spec_helper.rb +40 -8
  46. data/spec/support/http_library_adapters.rb +0 -262
  47. data/spec/support/shared_example_groups/http_library.rb +256 -0
  48. data/spec/support/{http_stubbing_adapter.rb → shared_example_groups/http_stubbing_adapter.rb} +15 -3
  49. data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +28 -0
  50. data/spec/support/{normalizers.rb → shared_example_groups/normalizers.rb} +3 -3
  51. data/spec/support/{version_checker.rb → shared_example_groups/version_checking.rb} +1 -1
  52. data/spec/vcr/cassette_spec.rb +80 -28
  53. data/spec/vcr/config_spec.rb +55 -8
  54. data/spec/vcr/deprecations/cassette_spec.rb +57 -0
  55. data/spec/vcr/deprecations/config_spec.rb +30 -0
  56. data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +7 -0
  57. data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +16 -0
  58. data/spec/vcr/extensions/net_http_response_spec.rb +1 -3
  59. data/spec/vcr/extensions/net_http_spec.rb +1 -3
  60. data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +1 -4
  61. data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +1 -4
  62. data/spec/vcr/http_stubbing_adapters/typhoeus_spec.rb +1 -4
  63. data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +1 -3
  64. data/spec/vcr/middleware/faraday_spec.rb +4 -4
  65. data/spec/vcr/middleware/rack_spec.rb +4 -4
  66. data/spec/vcr/structs/http_interaction_spec.rb +61 -0
  67. data/spec/vcr/structs/request_spec.rb +20 -2
  68. data/spec/vcr/structs/response_spec.rb +23 -1
  69. data/spec/vcr/structs/response_status_spec.rb +1 -1
  70. data/spec/vcr/{cucumber_tags_spec.rb → test_frameworks/cucumber_spec.rb} +12 -8
  71. data/spec/vcr/{rspec_spec.rb → test_frameworks/rspec_spec.rb} +0 -0
  72. data/spec/vcr/{hooks_spec.rb → util/hooks_spec.rb} +3 -3
  73. data/spec/vcr/util/internet_connection_spec.rb +3 -3
  74. data/spec/vcr_spec.rb +3 -3
  75. data/vcr.gemspec +5 -5
  76. metadata +149 -131
  77. data/Gemfile.lock +0 -155
  78. data/lib/vcr/deprecations.rb +0 -54
  79. data/spec/support/disable_warnings.rb +0 -12
  80. data/spec/support/temp_cassette_library_dir.rb +0 -16
  81. data/spec/support/webmock_macros.rb +0 -14
  82. data/spec/vcr/deprecations_spec.rb +0 -139
@@ -1,5 +1,4 @@
1
1
  shared_examples_for "an http stubbing adapter" do |supported_http_libraries, supported_request_match_attributes, *other|
2
- extend HttpLibrarySpecs
3
2
  before(:each) { VCR.stub!(:http_stubbing_adapter).and_return(subject) }
4
3
  subject { described_class }
5
4
 
@@ -44,6 +43,19 @@ shared_examples_for "an http stubbing adapter" do |supported_http_libraries, sup
44
43
  end
45
44
  end
46
45
 
46
+ describe '.stub_requests' do
47
+ let(:request) { VCR::Request.new(:get, 'http://example.com/') }
48
+ let(:status) { VCR::ResponseStatus.new(200, 'OK') }
49
+ let(:response) { VCR::Response.new(status) }
50
+ let(:interaction) { VCR::HTTPInteraction.new(request, response) }
51
+
52
+ it 'works when the request and response has no headers' do
53
+ expect {
54
+ subject.stub_requests([interaction], [:method, :uri])
55
+ }.not_to raise_error
56
+ end
57
+ end
58
+
47
59
  if other.include?(:needs_net_http_extension)
48
60
  describe '.request_uri' do
49
61
  it 'returns the uri for the given http request' do
@@ -61,7 +73,7 @@ shared_examples_for "an http stubbing adapter" do |supported_http_libraries, sup
61
73
  end
62
74
 
63
75
  describe '.request_stubbed? using specific match_attributes' do
64
- let(:interactions) { YAML.load(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', YAML_SERIALIZATION_VERSION, 'match_requests_on.yml'))) }
76
+ let(:interactions) { VCR::YAML.load_file(File.join(VCR::SPEC_ROOT, 'fixtures', YAML_SERIALIZATION_VERSION, 'match_requests_on.yml')) }
65
77
 
66
78
  @supported_request_match_attributes = supported_request_match_attributes
67
79
  def self.matching_on(attribute, valid1, valid2, invalid, &block)
@@ -128,7 +140,7 @@ shared_examples_for "an http stubbing adapter" do |supported_http_libraries, sup
128
140
  end
129
141
 
130
142
  supported_http_libraries.each do |library|
131
- test_http_library library, supported_request_match_attributes, *other
143
+ it_behaves_like 'an http library', library, supported_request_match_attributes, *other
132
144
  end
133
145
  end
134
146
 
@@ -0,0 +1,28 @@
1
+ shared_examples_for '.ignore_localhost? deprecation' do
2
+ it 'returns false when no hosts are ignored' do
3
+ VCR::Config.ignored_hosts.should be_empty
4
+ described_class.ignore_localhost?.should be_false
5
+ end
6
+
7
+ it 'returns false when only non-local hosts are ignored' do
8
+ VCR::Config.ignore_hosts 'example.com'
9
+ described_class.ignore_localhost?.should be_false
10
+ end
11
+
12
+ it 'returns false when only some localhost aliases are ignored' do
13
+ aliases = VCR::LOCALHOST_ALIASES.dup
14
+ aliases.pop
15
+ VCR::Config.ignore_hosts *aliases
16
+ described_class.ignore_localhost?.should be_false
17
+ end
18
+
19
+ it 'returns true when all localhost aliases are ignored, even if some other hosts are ignored, too' do
20
+ VCR::Config.ignore_hosts 'example.com', *VCR::LOCALHOST_ALIASES
21
+ described_class.ignore_localhost?.should be_true
22
+ end
23
+
24
+ it 'prints a warning: WARNING: `VCR::Config.ignore_localhost?` is deprecated. Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead.' do
25
+ VCR::Config.should_receive(:warn).with(/Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead/)
26
+ described_class.ignore_localhost?
27
+ end
28
+ end
@@ -28,14 +28,14 @@ shared_examples_for "header normalization" do
28
28
  key = 'my-key'
29
29
  key.instance_variable_set(:@foo, 7)
30
30
  instance = with_headers(key => ['value1'])
31
- instance.headers.to_yaml.should == { 'my-key' => ['value1'] }.to_yaml
31
+ VCR::YAML.dump(instance.headers).should == VCR::YAML.dump('my-key' => ['value1'])
32
32
  end
33
33
 
34
34
  it 'ensures header values are serialized to yaml as raw strings' do
35
35
  value = 'my-value'
36
36
  value.instance_variable_set(:@foo, 7)
37
37
  instance = with_headers('my-key' => [value])
38
- instance.headers.to_yaml.should == { 'my-key' => ['my-value'] }.to_yaml
38
+ VCR::YAML.dump(instance.headers).should == VCR::YAML.dump('my-key' => ['my-value'])
39
39
  end
40
40
  end
41
41
 
@@ -47,7 +47,7 @@ shared_examples_for "body normalization" do
47
47
  it "ensures the body is serialized to yaml as a raw string" do
48
48
  body = "My String"
49
49
  body.instance_variable_set(:@foo, 7)
50
- instance(body).body.to_yaml.should == "My String".to_yaml
50
+ VCR::YAML.dump(instance(body).body).should == VCR::YAML.dump("My String")
51
51
  end
52
52
  end
53
53
 
@@ -1,7 +1,7 @@
1
1
  shared_examples_for "version checking" do |options|
2
2
  library = described_class.library_name
3
3
 
4
- describe '.check_version!' do
4
+ describe '.check_version!', :disable_warnings => true do
5
5
  options[:valid].each do |version|
6
6
  it "does nothing when #{library}'s version is #{version}" do
7
7
  stub_version(version)
@@ -2,8 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe VCR::Cassette do
4
4
  describe '#file' do
5
- temp_dir "#{VCR::SPEC_ROOT}/fixtures/file", :assign_to_cassette_library_dir => true
6
-
7
5
  it 'combines the cassette_library_dir with the cassette name' do
8
6
  cassette = VCR::Cassette.new('the_file')
9
7
  cassette.file.should == File.join(VCR::Config.cassette_library_dir, 'the_file.yml')
@@ -89,7 +87,7 @@ describe VCR::Cassette do
89
87
  it 'reads the appropriate file from disk using a VCR::Cassette::Reader' do
90
88
  VCR::Cassette::Reader.should_receive(:new).with(
91
89
  'cassette_lib/foo.yml', anything
92
- ).and_return(mock('reader', :read => [].to_yaml))
90
+ ).and_return(mock('reader', :read => VCR::YAML.dump([])))
93
91
 
94
92
  VCR::Cassette.new('foo', :record => :new_episodes)
95
93
  end
@@ -101,7 +99,7 @@ describe VCR::Cassette do
101
99
 
102
100
  VCR::Cassette::Reader.should_receive(:new).with(
103
101
  anything, erb
104
- ).and_return(mock('reader', :read => [].to_yaml))
102
+ ).and_return(mock('reader', :read => VCR::YAML.dump([])))
105
103
 
106
104
  VCR::Cassette.new('foo', :record => :new_episodes, :erb => erb)
107
105
  end
@@ -111,7 +109,7 @@ describe VCR::Cassette do
111
109
 
112
110
  VCR::Cassette::Reader.should_receive(:new).with(
113
111
  anything, erb
114
- ).and_return(mock('reader', :read => [].to_yaml))
112
+ ).and_return(mock('reader', :read => VCR::YAML.dump([])))
115
113
 
116
114
  VCR::Cassette.new('foo', :record => :new_episodes)
117
115
  end
@@ -132,7 +130,55 @@ describe VCR::Cassette do
132
130
  end
133
131
 
134
132
  context "when :#{record_mode} is passed as the record option" do
133
+ if record_mode == :none
134
+ it 'does not allow http connections when there is an existing cassette file with recorded interactions' do
135
+ VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec"
136
+ VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(false)
137
+ c = VCR::Cassette.new('example', :record => :once)
138
+ File.should exist(c.file)
139
+ File.size?(c.file).should be_true
140
+ end
141
+
142
+ it 'allows http connections when there is an empty existing cassette file' do
143
+ VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec"
144
+ VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(true)
145
+ c = VCR::Cassette.new('empty', :record => :once)
146
+ File.should exist(c.file)
147
+ File.size?(c.file).should be_false
148
+ end
149
+
150
+ it 'allows http connections when there is not an existing cassette file' do
151
+ VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec"
152
+ VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(true)
153
+ c = VCR::Cassette.new('non_existant_file', :record => :once)
154
+ File.should_not exist(c.file)
155
+ end
156
+ end
157
+
135
158
  unless record_mode == :all
159
+ let(:interaction_1) { VCR::HTTPInteraction.new(VCR::Request.new(:get, 'http://example.com/'), VCR::Response.new(VCR::ResponseStatus.new)) }
160
+ let(:interaction_2) { VCR::HTTPInteraction.new(VCR::Request.new(:get, 'http://example.com/'), VCR::Response.new(VCR::ResponseStatus.new)) }
161
+ let(:interactions) { [interaction_1, interaction_2] }
162
+ before(:each) { VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec" }
163
+
164
+ it 'updates the content_length headers when given :update_content_length_header => true' do
165
+ VCR::YAML.stub(:load => interactions)
166
+ interaction_1.response.should_receive(:update_content_length_header)
167
+ interaction_2.response.should_receive(:update_content_length_header)
168
+
169
+ VCR::Cassette.new('example', :record => record_mode, :update_content_length_header => true)
170
+ end
171
+
172
+ [nil, false].each do |val|
173
+ it "does not update the content_lenth headers when given :update_content_length_header => #{val.inspect}" do
174
+ VCR::YAML.stub(:load => interactions)
175
+ interaction_1.response.should_not_receive(:update_content_length_header)
176
+ interaction_2.response.should_not_receive(:update_content_length_header)
177
+
178
+ VCR::Cassette.new('example', :record => record_mode, :update_content_length_header => val)
179
+ end
180
+ end
181
+
136
182
  context "and re_record_interval is 7.days" do
137
183
  let(:file_name) { File.join(VCR::Config.cassette_library_dir, "cassette_name.yml") }
138
184
  subject { VCR::Cassette.new(File.basename(file_name).gsub('.yml', ''), :record => record_mode, :re_record_interval => 7.days) }
@@ -148,7 +194,7 @@ describe VCR::Cassette do
148
194
  context 'when the cassette file does exist' do
149
195
  before(:each) do
150
196
  File.stub(:exist?).with(file_name).and_return(true)
151
- File.stub(:read).with(file_name).and_return([].to_yaml)
197
+ File.stub(:read).with(file_name).and_return(VCR::YAML.dump([]))
152
198
  end
153
199
 
154
200
  context 'and the file was last modified less than 7 days ago' do
@@ -258,8 +304,6 @@ describe VCR::Cassette do
258
304
  end
259
305
 
260
306
  describe '#eject' do
261
- temp_dir "#{VCR::SPEC_ROOT}/fixtures/cassette_spec_eject", :assign_to_cassette_library_dir => true
262
-
263
307
  [true, false].each do |orig_http_connections_allowed|
264
308
  it "resets #{orig_http_connections_allowed} on the http stubbing adapter if it was originally #{orig_http_connections_allowed}" do
265
309
  VCR.http_stubbing_adapter.should_receive(:http_connections_allowed?).and_return(orig_http_connections_allowed)
@@ -280,7 +324,7 @@ describe VCR::Cassette do
280
324
  cassette.stub!(:new_recorded_interactions).and_return(recorded_interactions)
281
325
 
282
326
  expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true)
283
- saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
327
+ saved_recorded_interactions = VCR::YAML.load_file(cassette.file)
284
328
  saved_recorded_interactions.should == recorded_interactions
285
329
  end
286
330
 
@@ -315,7 +359,7 @@ describe VCR::Cassette do
315
359
  cassette.stub!(:new_recorded_interactions).and_return([interaction_1, interaction_2])
316
360
  cassette.eject
317
361
 
318
- saved_recorded_interactions = YAML.load_file(cassette.file)
362
+ saved_recorded_interactions = VCR::YAML.load_file(cassette.file)
319
363
  saved_recorded_interactions.should == [interaction_2]
320
364
  end
321
365
 
@@ -336,19 +380,17 @@ describe VCR::Cassette do
336
380
  cassette.stub!(:new_recorded_interactions).and_return(recorded_interactions)
337
381
 
338
382
  expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true)
339
- saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
383
+ saved_recorded_interactions = VCR::YAML.load_file(cassette.file)
340
384
  saved_recorded_interactions.should == recorded_interactions
341
385
  end
342
386
 
343
387
  [:all, :none, :new_episodes].each do |record_mode|
344
388
  context "for a :record => :#{record_mode} cassette with previously recorded interactions" do
345
- temp_dir "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec/temp", :assign_to_cassette_library_dir => true
346
-
347
389
  subject { VCR::Cassette.new('example', :record => record_mode, :match_requests_on => [:uri]) }
348
390
 
349
391
  before(:each) do
350
392
  base_dir = "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec"
351
- FileUtils.cp(base_dir + "/example.yml", base_dir + "/temp/example.yml")
393
+ FileUtils.cp(base_dir + "/example.yml", VCR::Config.cassette_library_dir + "/example.yml")
352
394
  end
353
395
 
354
396
  it "restore the stubs checkpoint on the http stubbing adapter" do
@@ -371,16 +413,24 @@ describe VCR::Cassette do
371
413
  let(:old_interaction_2) { subject.recorded_interactions[1] }
372
414
  let(:old_interaction_3) { subject.recorded_interactions[2] }
373
415
 
374
- let(:saved_recorded_interactions) { YAML.load(File.read(subject.file)) }
416
+ let(:saved_recorded_interactions) { VCR::YAML.load_file(subject.file) }
417
+
418
+ def stub_matcher_for(interaction, matcher)
419
+ # There are issues with serializing an object stubbed w/ rspec-mocks using Psych.
420
+ # So we manually define the method here.
421
+ class << interaction.request; self; end.class_eval do
422
+ define_method(:matcher) { |*a| matcher }
423
+ end
424
+ end
375
425
 
376
426
  before(:each) do
377
- old_interaction_1.request.stub(:matcher => :matcher_c)
378
- old_interaction_2.request.stub(:matcher => :matcher_d)
379
- old_interaction_3.request.stub(:matcher => :matcher_c)
427
+ stub_matcher_for(old_interaction_1, :matcher_c)
428
+ stub_matcher_for(old_interaction_2, :matcher_d)
429
+ stub_matcher_for(old_interaction_3, :matcher_c)
380
430
 
381
- new_interaction_1.request.stub(:matcher => :matcher_a)
382
- new_interaction_2.request.stub(:matcher => :matcher_b)
383
- new_interaction_3.request.stub(:matcher => :matcher_c)
431
+ stub_matcher_for(new_interaction_1, :matcher_a)
432
+ stub_matcher_for(new_interaction_2, :matcher_b)
433
+ stub_matcher_for(new_interaction_3, :matcher_c)
384
434
 
385
435
  [new_interaction_1, new_interaction_2, new_interaction_3].each do |i|
386
436
  subject.record_http_interaction(i)
@@ -400,14 +450,16 @@ describe VCR::Cassette do
400
450
  end
401
451
 
402
452
  it "matches old requests to new ones using the cassette's match attributes" do
403
- [
404
- old_interaction_1, old_interaction_2, old_interaction_3,
405
- new_interaction_1, new_interaction_2, new_interaction_3
406
- ].each do |i|
407
- i.request.should_receive(:matcher).with(subject.match_requests_on).and_return(:the_matcher)
408
- end
453
+ pending("Need to fix this to work with Psych", :if => defined?(::Psych)) do
454
+ [
455
+ old_interaction_1, old_interaction_2, old_interaction_3,
456
+ new_interaction_1, new_interaction_2, new_interaction_3
457
+ ].each do |i|
458
+ i.request.should_receive(:matcher).with(subject.match_requests_on).and_return(:the_matcher)
459
+ end
409
460
 
410
- subject.eject
461
+ subject.eject
462
+ end
411
463
  end
412
464
  else
413
465
  it 'saves the old interactions followed by the new ones to disk' do
@@ -7,10 +7,11 @@ describe VCR::Config do
7
7
  end
8
8
 
9
9
  describe '.cassette_library_dir=' do
10
- temp_dir(File.expand_path(File.dirname(__FILE__) + '/fixtures/config_spec'))
11
-
12
10
  it 'creates the directory if it does not exist' do
13
- expect { VCR::Config.cassette_library_dir = @temp_dir }.to change { File.exist?(@temp_dir) }.from(false).to(true)
11
+ Dir.mktmpdir do |dir|
12
+ dir += '/cassettes'
13
+ expect { VCR::Config.cassette_library_dir = dir }.to change { File.exist?(dir) }.from(false).to(true)
14
+ end
14
15
  end
15
16
 
16
17
  it 'does not raise an error if given nil' do
@@ -21,15 +22,20 @@ describe VCR::Config do
21
22
  describe '.default_cassette_options' do
22
23
  it 'has a hash with some defaults even if it is set to nil' do
23
24
  VCR::Config.default_cassette_options = nil
24
- VCR::Config.default_cassette_options.should == { :match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES }
25
+ VCR::Config.default_cassette_options.should == {
26
+ :match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES,
27
+ :record => :once
28
+ }
25
29
  end
26
30
 
27
31
  it "returns #{VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES.inspect} for :match_requests_on when other defaults have been set" do
28
32
  VCR::Config.default_cassette_options = { :record => :none }
29
- VCR::Config.default_cassette_options.should == {
30
- :record => :none,
31
- :match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES
32
- }
33
+ VCR::Config.default_cassette_options.should include(:match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES)
34
+ end
35
+
36
+ it "returns :once for :record when other defaults have been set" do
37
+ VCR::Config.default_cassette_options = { :erb => :true }
38
+ VCR::Config.default_cassette_options.should include(:record => :once)
33
39
  end
34
40
  end
35
41
 
@@ -131,4 +137,45 @@ describe VCR::Config do
131
137
  described_class.uri_should_be_ignored?(URI("http://example.net/")).should be_false
132
138
  end
133
139
  end
140
+
141
+ describe '.filter_sensitive_data' do
142
+ let(:interaction) { mock('interaction') }
143
+ before(:each) { interaction.stub(:filter!) }
144
+
145
+ it 'adds a before_record hook that replaces the string returned by the block with the given string' do
146
+ described_class.filter_sensitive_data('foo', &lambda { 'bar' })
147
+ interaction.should_receive(:filter!).with('bar', 'foo')
148
+ described_class.invoke_hook(:before_record, nil, interaction)
149
+ end
150
+
151
+ it 'adds a before_playback hook that replaces the given string with the string returned by the block' do
152
+ described_class.filter_sensitive_data('foo', &lambda { 'bar' })
153
+ interaction.should_receive(:filter!).with('foo', 'bar')
154
+ described_class.invoke_hook(:before_playback, nil, interaction)
155
+ end
156
+
157
+ it 'tags the before_record hook when given a tag' do
158
+ described_class.should_receive(:before_record).with(:my_tag)
159
+ described_class.filter_sensitive_data('foo', :my_tag) { 'bar' }
160
+ end
161
+
162
+ it 'tags the before_playback hook when given a tag' do
163
+ described_class.should_receive(:before_playback).with(:my_tag)
164
+ described_class.filter_sensitive_data('foo', :my_tag) { 'bar' }
165
+ end
166
+
167
+ it 'yields the interaction to the block for the before_record hook' do
168
+ yielded_interaction = nil
169
+ described_class.filter_sensitive_data('foo', &lambda { |i| yielded_interaction = i; 'bar' })
170
+ described_class.invoke_hook(:before_record, nil, interaction)
171
+ yielded_interaction.should equal(interaction)
172
+ end
173
+
174
+ it 'yields the interaction to the block for the before_playback hook' do
175
+ yielded_interaction = nil
176
+ described_class.filter_sensitive_data('foo', &lambda { |i| yielded_interaction = i; 'bar' })
177
+ described_class.invoke_hook(:before_playback, nil, interaction)
178
+ yielded_interaction.should equal(interaction)
179
+ end
180
+ end
134
181
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe VCR::Cassette, 'deprecations', :disable_warnings => true do
4
+
5
+ subject { VCR::Cassette.new('cassette name') }
6
+
7
+ it 'raises an error when an :allow_real_http lambda is given' do
8
+ expect { VCR::Cassette.new('cassette name', :allow_real_http => lambda {}) }.to raise_error(ArgumentError)
9
+ end
10
+
11
+ it "prints a warning: WARNING: VCR::Cassette#allow_real_http_requests_to? is deprecated and should no longer be used" do
12
+ subject.should_receive(:warn).with("WARNING: VCR::Cassette#allow_real_http_requests_to? is deprecated and should no longer be used.")
13
+ subject.allow_real_http_requests_to?(URI.parse('http://example.org'))
14
+ end
15
+
16
+ [true, false].each do |orig_ignore_localhost|
17
+ orig_ignored_hosts = if orig_ignore_localhost
18
+ VCR::LOCALHOST_ALIASES
19
+ else
20
+ []
21
+ end
22
+
23
+ context "when the ignored_hosts list is set to #{orig_ignored_hosts.inspect} and the :allow_real_http option is set to :localhost" do
24
+ before(:each) do
25
+ VCR::Config.ignored_hosts.clear
26
+ VCR::Config.ignore_hosts *orig_ignored_hosts
27
+ end
28
+
29
+ subject { VCR::Cassette.new('cassette name', :allow_real_http => :localhost) }
30
+
31
+ it "sets the ignored_hosts list to the list of localhost aliases" do
32
+ subject
33
+ VCR::Config.ignored_hosts.should == VCR::LOCALHOST_ALIASES
34
+ end
35
+
36
+ it "prints a warning: VCR's :allow_real_http cassette option is deprecated. Instead, use the ignore_localhost configuration option." do
37
+ Kernel.should_receive(:warn).with("WARNING: VCR's :allow_real_http cassette option is deprecated. Instead, use the ignore_localhost configuration option.")
38
+ subject
39
+ end
40
+
41
+ it "reverts ignore_hosts when the cassette is ejected" do
42
+ subject.eject
43
+ VCR::Config.ignored_hosts.should == orig_ignored_hosts
44
+ end
45
+
46
+ {
47
+ 'http://localhost' => true,
48
+ 'http://127.0.0.1' => true,
49
+ 'http://example.com' => false
50
+ }.each do |url, expected_value|
51
+ it "returns #{expected_value} for #allow_real_http_requests_to? when it is given #{url}" do
52
+ subject.allow_real_http_requests_to?(URI.parse(url)).should == expected_value
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end