Mock Rails root

This commit is contained in:
Karina Kwiatek 2022-07-10 12:01:00 +02:00 committed by Karina Kwiatek
parent 13d4927461
commit f244252ade
1 changed files with 4 additions and 1 deletions

View File

@ -104,6 +104,8 @@ RSpec.describe Exporter do
end end
describe "#finalize" do describe "#finalize" do
let(:fake_rails_root) { Pathname(Dir.mktmpdir) }
before do before do
instance.instance_variable_set(:@obj, { instance.instance_variable_set(:@obj, {
some: { some: {
@ -112,6 +114,7 @@ RSpec.describe Exporter do
} }
} }
}) })
allow(Rails).to receive(:root).and_return(fake_rails_root)
end end
subject { instance.send(:finalize) } subject { instance.send(:finalize) }
@ -122,7 +125,7 @@ RSpec.describe Exporter do
it "prepares files to be archived" do it "prepares files to be archived" do
subject subject
expect(File.directory?(Rails.root.join("public/export"))).to eq(true) expect(File.directory?(fake_rails_root.join("public/export"))).to eq(true)
expect(File.directory?("#{dir}/pictures")).to eq(true) expect(File.directory?("#{dir}/pictures")).to eq(true)
end end