Skip to content

Commit d136254

Browse files
committed
Fully qualify File constant to avoid wonky 1.9.2 const resolution issue.
See rspec/rspec-core#1697 for more details.
1 parent 3e7fdb7 commit d136254

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

spec/vcr/cassette_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,21 @@ def stub_old_interactions(interactions)
113113

114114
it 'returns false when there is an existing cassette file with content' do
115115
cassette = VCR::Cassette.new("example", :record => :once)
116-
expect(File).to exist(cassette.file)
117-
expect(File.size?(cassette.file)).to be_truthy
116+
expect(::File).to exist(cassette.file)
117+
expect(::File.size?(cassette.file)).to be_truthy
118118
expect(cassette).not_to be_recording
119119
end
120120

121121
it 'returns true when there is an empty existing cassette file' do
122122
cassette = VCR::Cassette.new("empty", :record => :once)
123-
expect(File).to exist(cassette.file)
124-
expect(File.size?(cassette.file)).to be_falsey
123+
expect(::File).to exist(cassette.file)
124+
expect(::File.size?(cassette.file)).to be_falsey
125125
expect(cassette).to be_recording
126126
end
127127

128128
it 'returns true when there is no existing cassette file' do
129129
cassette = VCR::Cassette.new("non_existant_file", :record => :once)
130-
expect(File).not_to exist(cassette.file)
130+
expect(::File).not_to exist(cassette.file)
131131
expect(cassette).to be_recording
132132
end
133133
end
@@ -253,11 +253,11 @@ def stub_old_interactions(interactions)
253253
end
254254

255255
context "and re_record_interval is 7.days" do
256-
let(:file_name) { File.join(VCR.configuration.cassette_library_dir, "cassette_name.yml") }
257-
subject { VCR::Cassette.new(File.basename(file_name).gsub('.yml', ''), :record => record_mode, :re_record_interval => 7.days) }
256+
let(:file_name) { ::File.join(VCR.configuration.cassette_library_dir, "cassette_name.yml") }
257+
subject { VCR::Cassette.new(::File.basename(file_name).gsub('.yml', ''), :record => record_mode, :re_record_interval => 7.days) }
258258

259259
context 'when the cassette file does not exist' do
260-
before(:each) { allow(File).to receive(:exist?).with(file_name).and_return(false) }
260+
before(:each) { allow(::File).to receive(:exist?).with(file_name).and_return(false) }
261261

262262
it "has :#{record_mode} for the record mode" do
263263
expect(subject.record_mode).to eq(record_mode)
@@ -271,9 +271,9 @@ def stub_old_interactions(interactions)
271271
end
272272
yaml = YAML.dump("http_interactions" => interactions)
273273

274-
allow(File).to receive(:exist?).with(file_name).and_return(true)
275-
allow(File).to receive(:size?).with(file_name).and_return(true)
276-
allow(File).to receive(:read).with(file_name).and_return(yaml)
274+
allow(::File).to receive(:exist?).with(file_name).and_return(true)
275+
allow(::File).to receive(:size?).with(file_name).and_return(true)
276+
allow(::File).to receive(:read).with(file_name).and_return(yaml)
277277
end
278278

279279
context 'and the earliest recorded interaction was recorded less than 7 days ago' do
@@ -490,7 +490,7 @@ def stub_old_interactions(interactions)
490490
expect(cassette).to respond_to(:serializable_hash)
491491
allow(cassette).to receive(:serializable_hash).and_return({ "http_interactions" => [1, 3, 5] })
492492

493-
expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true)
493+
expect { cassette.eject }.to change { ::File.exist?(cassette.file) }.from(false).to(true)
494494
saved_stuff = YAML.load_file(cassette.file)
495495
expect(saved_stuff).to eq("http_interactions" => [1, 3, 5])
496496
end
@@ -544,15 +544,15 @@ def stub_old_interactions(interactions)
544544
allow(cassette).to receive(:new_recorded_interactions).and_return([interaction_1])
545545
cassette.eject
546546

547-
expect(File).not_to exist(cassette.file)
547+
expect(::File).not_to exist(cassette.file)
548548
end
549549

550550
it "writes the recorded interactions to a subdirectory if the cassette name includes a directory" do
551551
recorded_interactions = [http_interaction { |i| i.response.body = "subdirectory response" }]
552552
cassette = VCR::Cassette.new('subdirectory/test_cassette')
553553
allow(cassette).to receive(:new_recorded_interactions).and_return(recorded_interactions)
554554

555-
expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true)
555+
expect { cassette.eject }.to change { ::File.exist?(cassette.file) }.from(false).to(true)
556556
saved_recorded_interactions = YAML.load_file(cassette.file)
557557
expect(saved_recorded_interactions["http_interactions"]).to eq(recorded_interactions.map(&:to_hash))
558558
end
@@ -568,8 +568,8 @@ def stub_old_interactions(interactions)
568568

569569
it "does not re-write to disk the previously recorded interactions if there are no new ones" do
570570
yaml_file = subject.file
571-
expect(File).not_to receive(:open).with(subject.file, 'w')
572-
expect { subject.eject }.to_not change { File.mtime(yaml_file) }
571+
expect(::File).not_to receive(:open).with(subject.file, 'w')
572+
expect { subject.eject }.to_not change { ::File.mtime(yaml_file) }
573573
end
574574

575575
context 'when some new interactions have been recorded' do

0 commit comments

Comments
 (0)