How to use storage_location method of VCR Package

Best Vcr_ruby code snippet using VCR.storage_location


Source:persister_spec.rb Github


Full Screen

...3 module Gzip4 describe Persister do5 describe "#[]" do6 it 'gunzips and reads from the given file' do7 file_path = Persister.storage_location + '/foo.txt.gz'8 do |gz|9 gz.write('12345')10 end11 Persister["foo.txt"].should eq("12345")12 end13 it 'handles directories in the given file name' do14 FileUtils.mkdir_p Persister.storage_location + '/a'15 + '/a/b.gz') do |gz|16 gz.write('1234')17 end18 Persister["a/b"].should eq("1234")19 end20 it 'returns nil if the file does not exist' do21 Persister["non_existant_file"].should be_nil22 end23 end24 describe "#[]=" do25 it 'gzips and writes the given file contents to the given file name' do26 file_path = Persister.storage_location + '/foo.txt.gz'27 File.exist?(file_path).should be_false28 Persister["foo.txt"] = "bar"29 { |gz| eq("bar") }30 end31 it 'creates any needed intermediary directories' do32 File.exist?(Persister.storage_location + '/a').should be_false33 Persister["a/b"] = "bar"34 file_path = Persister.storage_location + '/a/b.gz'35 { |gz| eq("bar") }36 end37 end38 describe "#storage_location" do39 before do40 @previous_location = Persister.storage_location41 @previous_default_location = VCR.configuration.cassette_library_dir42 end43 after do44 Persister.storage_location = @previous_location45 VCR.configuration.cassette_library_dir = @previous_default_location46 end47 it "returns VCR.configuration.cassette_library_dir by default" do48 default_location = @previous_default_location + '/default_location'49 VCR::Cassette::Persisters::FileSystem.storage_location = default_location50 Persister.storage_location.should == default_location51 end52 it "allows overwriting the default location" do53 location = @previous_default_location + '/overwritten_location'54 Persister.storage_location = location55 Persister.storage_location.should == location56 end57 it "raises an exception if no location is defined and default is not present" do58 VCR::Cassette::Persisters::FileSystem.storage_location = nil59 Persister.storage_location = nil60 expect {61 Persister.storage_location62 }.to raise_error(/Vcr::Gzip::Persister.storage_location is missing./)63 end64 end65 describe "#absolute_path_to_file" do66 it "returns the absolute path to file relative to the storage location with .gz extension" do67 expected = File.join(Persister.storage_location, "bar/bazz.json.gz")68 Persister.absolute_path_to_file("bar/bazz.json").should eq(expected)69 end70 it "sanitizes the file name" do71 expected = File.join(Persister.storage_location, "_t_i-t_1_2_f_n.json.gz")72 Persister.absolute_path_to_file("\nt \t! i-t_1.2_f n.json").should eq(expected)73 expected = File.join(Persister.storage_location, "a_1/b.gz")74 Persister.absolute_path_to_file("a 1/b").should eq(expected)75 end76 end77 end78 end79end...

Full Screen

Full Screen


Source:file_system_spec.rb Github


Full Screen

...3module VCR4 class Cassette5 class Persisters6 describe FileSystem do7 before { FileSystem.storage_location = VCR.configuration.cassette_library_dir }8 describe "#[]" do9 it 'reads from the given file, relative to the configured storage location' do10 + '/foo.txt', 'w') { |f| f.write('1234') }11 expect(FileSystem["foo.txt"]).to eq("1234")12 end13 it 'handles directories in the given file name' do14 FileUtils.mkdir_p FileSystem.storage_location + '/a'15 + '/a/b', 'w') { |f| f.write('1234') }16 expect(FileSystem["a/b"]).to eq("1234")17 end18 it 'returns nil if the file does not exist' do19 expect(FileSystem["non_existant_file"]).to be_nil20 end21 end22 describe "#[]=" do23 context 'with a simple file_name and binary content' do24 let(:file_name) { 'foo.txt' }25 let(:content) { SecureRandom.random_bytes(20) }26 let(:location) { FileSystem.storage_location + '/' + file_name }27 it 'writes the given file contents to the given file name' do28 expect(File.exist?(location)).to be false29 FileSystem[file_name] = content30 expect(File.binread(location)).to eq(content)31 end32 end33 it 'creates any needed intermediary directories' do34 expect(File.exist?(FileSystem.storage_location + '/a')).to be false35 FileSystem["a/b"] = "bar"36 expect( + '/a/b')).to eq("bar")37 end38 end39 describe "#absolute_path_to_file" do40 it "returns the absolute path to the given relative file based on the storage location" do41 expected = File.join(FileSystem.storage_location, "bar/bazz.json")42 expect(FileSystem.absolute_path_to_file("bar/bazz.json")).to eq(expected)43 end44 it "returns nil if the storage_location is not set" do45 FileSystem.storage_location = nil46 expect(FileSystem.absolute_path_to_file("bar/bazz.json")).to be_nil47 end48 it "sanitizes the file name" do49 expected = File.join(FileSystem.storage_location, "_t_i-t_1_2_f_n.json")50 expect(FileSystem.absolute_path_to_file("\nt \t! i-t_1.2_f n.json")).to eq(expected)51 expected = File.join(FileSystem.storage_location, "a_1/b")52 expect(FileSystem.absolute_path_to_file("a 1/b")).to eq(expected)53 end54 it 'handles files with no extensions (even when there is a dot in the path)' do55 expected = File.join(FileSystem.storage_location, "/foo_bar/baz_qux")56 expect(FileSystem.absolute_path_to_file("/ qux")).to eq(expected)57 end58 end59 end60 end61 end62end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Vcr_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?