Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed the configuration option to have a default_cassette_options h…

…ash. #default_cassette_record_mode is deprecated.
  • Loading branch information...
commit a35de86a9608752db56c31b8d3eee5635ed5cef1 1 parent 4c09544
@myronmarston authored
View
2  lib/vcr/cassette.rb
@@ -9,7 +9,7 @@ class Cassette
def initialize(name, options = {})
@name = name
- @record_mode = options[:record] || VCR::Config.default_cassette_record_mode
+ @record_mode = options[:record] || VCR::Config.default_cassette_options[:record]
self.class.raise_error_unless_valid_record_mode(record_mode)
set_fakeweb_allow_net_connect
load_recorded_responses
View
12 lib/vcr/config.rb
@@ -9,10 +9,14 @@ def cache_dir=(cache_dir)
FileUtils.mkdir_p(cache_dir) if cache_dir
end
- attr_reader :default_cassette_record_mode
- def default_cassette_record_mode=(default_cassette_record_mode)
- VCR::Cassette.raise_error_unless_valid_record_mode(default_cassette_record_mode)
- @default_cassette_record_mode = default_cassette_record_mode
+ attr_writer :default_cassette_options
+ def default_cassette_options
+ @default_cassette_options ||= {}
+ end
+
+ def default_cassette_record_mode=(value)
+ warn %Q{WARNING: #default_cassette_record_mode is deprecated. Instead, use: "default_cassette_options = { :record => :#{value.to_s} }"}
+ default_cassette_options.merge!(:record => value)
end
end
end
View
9 spec/cassette_spec.rb
@@ -2,12 +2,11 @@
describe VCR::Cassette do
before(:all) do
- @orig_default_cassette_record_mode = VCR::Config.default_cassette_record_mode
- VCR::Config.default_cassette_record_mode = :unregistered
+ VCR::Config.default_cassette_options = { :record => :unregistered }
end
after(:all) do
- VCR::Config.default_cassette_record_mode = :unregistered
+ VCR::Config.default_cassette_options = { :record => :unregistered }
end
before(:each) do
@@ -55,8 +54,8 @@
end
VCR::Cassette::VALID_RECORD_MODES.each do |mode|
- it "defaults the record mode to #{mode} when VCR::Config.default_cassette_record_mode is #{mode}" do
- VCR::Config.default_cassette_record_mode = mode
+ it "defaults the record mode to #{mode} when VCR::Config.default_cassette_options[:record] is #{mode}" do
+ VCR::Config.default_cassette_options = { :record => mode }
cassette = VCR::Cassette.new(:test)
cassette.record_mode.should == mode
end
View
32 spec/config_spec.rb
@@ -13,15 +13,35 @@
end
end
- describe '#default_cassette_record_mode' do
- VCR::Cassette::VALID_RECORD_MODES.each do |mode|
- it "allows #{mode}" do
- lambda { VCR::Config.default_cassette_record_mode = mode }.should_not raise_error
+ describe '#default_cassette_options' do
+ it 'always has a hash, even if it is set to nil' do
+ VCR::Config.default_cassette_options = nil
+ VCR::Config.default_cassette_options.should == {}
+ end
+ end
+
+ describe '#default_cassette_record_mode=' do
+ disable_warnings
+
+ it 'sets the default_cassette_options[:record] option' do
+ VCR::Cassette::VALID_RECORD_MODES.each do |mode|
+ VCR::Config.default_cassette_options = nil
+ VCR::Config.default_cassette_record_mode = mode
+ VCR::Config.default_cassette_options[:record].should == mode
end
end
- it "does not allow :not_a_record_mode" do
- lambda { VCR::Config.default_cassette_record_mode = :not_a_record_mode }.should raise_error(ArgumentError)
+ it 'merges the :record option with the existing default_cassette_record options' do
+ VCR::Config.default_cassette_options = { :an => :option }
+ VCR::Config.default_cassette_record_mode = :all
+ VCR::Config.default_cassette_options.should == { :an => :option, :record => :all }
+ end
+
+ it 'warns the user that it is deprecated' do
+ VCR::Cassette::VALID_RECORD_MODES.each do |mode|
+ VCR::Config.should_receive(:warn).with(%Q{WARNING: #default_cassette_record_mode is deprecated. Instead, use: "default_cassette_options = { :record => :#{mode.to_s} }"})
+ VCR::Config.default_cassette_record_mode = mode
+ end
end
end
end
View
1  spec/spec_helper.rb
@@ -19,4 +19,5 @@
Spec::Runner.configure do |config|
config.extend TempCacheDir
+ config.extend DisableWarnings
end
View
12 spec/support/disable_warnings.rb
@@ -0,0 +1,12 @@
+module DisableWarnings
+ def disable_warnings
+ before(:all) do
+ @orig_std_err = $stderr
+ $stderr = StringIO.new
+ end
+
+ after(:all) do
+ $stderr = @orig_std_err
+ end
+ end
+end
View
5 spec/vcr_spec.rb
@@ -2,12 +2,11 @@
describe VCR do
before(:all) do
- @orig_default_cassette_record_mode = VCR::Config.default_cassette_record_mode
- VCR::Config.default_cassette_record_mode = :unregistered
+ VCR::Config.default_cassette_options = { :record => :unregistered }
end
after(:all) do
- VCR::Config.default_cassette_record_mode = :unregistered
+ VCR::Config.default_cassette_options = { :record => :unregistered }
end
def create_cassette
Please sign in to comment.
Something went wrong with that request. Please try again.