From f244252ade6ae93baa1117a7862505202640e70b Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 10 Jul 2022 12:01:00 +0200 Subject: [PATCH] Mock Rails root --- spec/lib/exporter_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/lib/exporter_spec.rb b/spec/lib/exporter_spec.rb index b4f3915c..a8065924 100644 --- a/spec/lib/exporter_spec.rb +++ b/spec/lib/exporter_spec.rb @@ -104,6 +104,8 @@ RSpec.describe Exporter do end describe "#finalize" do + let(:fake_rails_root) { Pathname(Dir.mktmpdir) } + before do instance.instance_variable_set(:@obj, { some: { @@ -112,6 +114,7 @@ RSpec.describe Exporter do } } }) + allow(Rails).to receive(:root).and_return(fake_rails_root) end subject { instance.send(:finalize) } @@ -122,7 +125,7 @@ RSpec.describe Exporter do it "prepares files to be archived" do 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) end