Light Mode Dark Mode


You can use the #copy_to(destination) method to copy the fixture file to the destination path. The #copy_to method expects a path or string. See examples at FileUtils#cp method, which this method basically wraps. By using #copy_to, you can achieve faster file copying compared to the File#read then File#write approach, as it avoids loading the entire file into memory.

subject { }

let(:example_fixture) { fixture('example.json') }
let(:destination_path) { File.join(Dir.mktmpdir, 'path/to/destination/copied.json') }

before { example_fixture.copy_to(destination_path) }

after { File.unlink(destination_path) }

it { eql '{"key":"value"}' }
"key": "value"

Documentation generated by rspec-documentation