Skip to content

Commit

Permalink
Ensure the cassette_library_dir is isolated for all specs.
Browse files Browse the repository at this point in the history
Trying to get builds to pass on travis-ci.org exposed some ordering dependencies between specs because of this setting.
  • Loading branch information
myronmarston committed Feb 17, 2011
1 parent d84800a commit 8496313
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
9 changes: 8 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def reset!(stubbing_lib = :fakeweb)
end

RSpec.configure do |config|
config.extend TempCassetteLibraryDir
config.extend DisableWarnings
config.extend MonkeyPatches::RSpecMacros
config.extend WebMockMacros
Expand All @@ -59,6 +58,14 @@ def reset!(stubbing_lib = :fakeweb)
VCR::HttpStubbingAdapters::Faraday.reset!
end

# Ensure each example uses a different cassette library to keep them isolated.
config.around(:each) do |example|
Dir.mktmpdir do |dir|
VCR::Config.cassette_library_dir = dir
example.run
end
end

config.after(:each) do
VCR::HttpStubbingAdapters::Common.adapters.each do |a|
a.ignored_hosts = []
Expand Down
16 changes: 0 additions & 16 deletions spec/support/temp_cassette_library_dir.rb

This file was deleted.

9 changes: 2 additions & 7 deletions spec/vcr/cassette_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

describe VCR::Cassette do
describe '#file' do
temp_dir "#{VCR::SPEC_ROOT}/fixtures/file", :assign_to_cassette_library_dir => true

it 'combines the cassette_library_dir with the cassette name' do
cassette = VCR::Cassette.new('the_file')
cassette.file.should == File.join(VCR::Config.cassette_library_dir, 'the_file.yml')
Expand Down Expand Up @@ -161,6 +159,7 @@
let(:interaction_1) { VCR::HTTPInteraction.new(VCR::Request.new(:get, 'http://example.com/'), VCR::Response.new(VCR::ResponseStatus.new)) }
let(:interaction_2) { VCR::HTTPInteraction.new(VCR::Request.new(:get, 'http://example.com/'), VCR::Response.new(VCR::ResponseStatus.new)) }
let(:interactions) { [interaction_1, interaction_2] }
before(:each) { VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec" }

it 'updates the content_length headers when given :update_content_length_header => true' do
VCR::YAML.stub(:load => interactions)
Expand Down Expand Up @@ -305,8 +304,6 @@
end

describe '#eject' do
temp_dir "#{VCR::SPEC_ROOT}/fixtures/cassette_spec_eject", :assign_to_cassette_library_dir => true

[true, false].each do |orig_http_connections_allowed|
it "resets #{orig_http_connections_allowed} on the http stubbing adapter if it was originally #{orig_http_connections_allowed}" do
VCR.http_stubbing_adapter.should_receive(:http_connections_allowed?).and_return(orig_http_connections_allowed)
Expand Down Expand Up @@ -389,13 +386,11 @@

[:all, :none, :new_episodes].each do |record_mode|
context "for a :record => :#{record_mode} cassette with previously recorded interactions" do
temp_dir "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec/temp", :assign_to_cassette_library_dir => true

subject { VCR::Cassette.new('example', :record => record_mode, :match_requests_on => [:uri]) }

before(:each) do
base_dir = "#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec"
FileUtils.cp(base_dir + "/example.yml", base_dir + "/temp/example.yml")
FileUtils.cp(base_dir + "/example.yml", VCR::Config.cassette_library_dir + "/example.yml")
end

it "restore the stubs checkpoint on the http stubbing adapter" do
Expand Down
7 changes: 4 additions & 3 deletions spec/vcr/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ def stub_no_http_stubbing_adapter
end

describe '.cassette_library_dir=' do
temp_dir(File.expand_path(File.dirname(__FILE__) + '/fixtures/config_spec'))

it 'creates the directory if it does not exist' do
expect { VCR::Config.cassette_library_dir = @temp_dir }.to change { File.exist?(@temp_dir) }.from(false).to(true)
Dir.mktmpdir do |dir|
dir += '/cassettes'
expect { VCR::Config.cassette_library_dir = dir }.to change { File.exist?(dir) }.from(false).to(true)
end
end

it 'does not raise an error if given nil' do
Expand Down

0 comments on commit 8496313

Please sign in to comment.