diff --git a/spec/helpers/storage.rb b/spec/helpers/storage.rb index f05ec38..34284cb 100644 --- a/spec/helpers/storage.rb +++ b/spec/helpers/storage.rb @@ -8,6 +8,8 @@ def tmp_storage_dir end def setup_storage + allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) + FileUtils.rm_rf tmp_storage_dir FileUtils.mkdir_p tmp_storage_dir FileUtils.cp_r fixture('app'), tmp_storage_dir diff --git a/spec/helpers/tika_config.rb b/spec/helpers/tika_config.rb new file mode 100644 index 0000000..342829a --- /dev/null +++ b/spec/helpers/tika_config.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'fileutils' +require 'pathname' + +def tmp_tika_config_dir + Pathname.new("/tmp/colore_test.#{Process.pid}.tika") +end + +def setup_tika_config + allow(Colore::C_.config).to receive(:tika_config_directory).and_return tmp_tika_config_dir + + FileUtils.rm_rf tmp_tika_config_dir + FileUtils.mkdir_p tmp_tika_config_dir +end + +def delete_tika_config + FileUtils.rm_rf tmp_tika_config_dir +end diff --git a/spec/integration/standard_tasks_spec.rb b/spec/integration/standard_tasks_spec.rb index 14d8e01..4d317fc 100644 --- a/spec/integration/standard_tasks_spec.rb +++ b/spec/integration/standard_tasks_spec.rb @@ -5,7 +5,6 @@ RSpec.describe 'Standard Heathen tasks:' do before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) end after do diff --git a/spec/lib/app_spec.rb b/spec/lib/app_spec.rb index 8e3df79..090311b 100644 --- a/spec/lib/app_spec.rb +++ b/spec/lib/app_spec.rb @@ -29,7 +29,6 @@ def show_backtrace(response) before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) allow(Colore::Sidekiq::ConversionWorker).to receive(:perform_async) end diff --git a/spec/lib/colore/sidekiq/callback_worker_spec.rb b/spec/lib/colore/sidekiq/callback_worker_spec.rb index bea37ea..8dd6c6a 100644 --- a/spec/lib/colore/sidekiq/callback_worker_spec.rb +++ b/spec/lib/colore/sidekiq/callback_worker_spec.rb @@ -10,7 +10,6 @@ before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) end after do diff --git a/spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb b/spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb index 8813a0f..0c3a34e 100644 --- a/spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb +++ b/spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb @@ -5,7 +5,6 @@ RSpec.describe Colore::Sidekiq::LegacyPurgeWorker do before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) allow(Colore::C_.config).to receive(:legacy_purge_days).and_return(2) end diff --git a/spec/lib/converter_spec.rb b/spec/lib/converter_spec.rb index a57c26a..0909a0f 100644 --- a/spec/lib/converter_spec.rb +++ b/spec/lib/converter_spec.rb @@ -15,7 +15,6 @@ before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) allow(Heathen::Converter).to receive(:new).and_return(stubbed_converter) end diff --git a/spec/lib/legacy_converter_spec.rb b/spec/lib/legacy_converter_spec.rb index de57e25..c838331 100644 --- a/spec/lib/legacy_converter_spec.rb +++ b/spec/lib/legacy_converter_spec.rb @@ -10,7 +10,6 @@ before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) stubbed_converter = instance_double(Heathen::Converter, convert: "The quick brown fox") allow(Heathen::Converter).to receive(:new).and_return(stubbed_converter) end diff --git a/spec/lib/tika_config_spec.rb b/spec/lib/tika_config_spec.rb index 455c743..46ca73b 100644 --- a/spec/lib/tika_config_spec.rb +++ b/spec/lib/tika_config_spec.rb @@ -5,17 +5,12 @@ require 'pathname' RSpec.describe Colore::TikaConfig do - let(:tika_config_directory) { '../tmp/tika-test' } - let(:tika_test_config_path) { Pathname.new(File.expand_path('../../tmp/tika-test', __dir__)) } - before do - allow(Colore::C_.config).to receive(:tika_config_directory).and_return tika_config_directory - FileUtils.mkdir_p tika_test_config_path - FileUtils.rm_rf tika_test_config_path + setup_tika_config end after do - FileUtils.rm_rf tika_test_config_path + delete_tika_config end describe '.path_for' do @@ -29,7 +24,7 @@ end it 'returns the correct configuration file path' do - expect(path_for).to eq tika_test_config_path.join('ocr', described_class::VERSION, 'tika.fra.xml') + expect(path_for).to eq tmp_tika_config_dir.join('ocr', described_class::VERSION, 'tika.fra.xml') end end @@ -37,7 +32,7 @@ let(:language) { 'unknown' } it 'returns the default configuration file path' do - expect(path_for).to eq tika_test_config_path.join('ocr', described_class::VERSION, "tika.#{described_class::DEFAULT_LANGUAGE}.xml") + expect(path_for).to eq tmp_tika_config_dir.join('ocr', described_class::VERSION, "tika.#{described_class::DEFAULT_LANGUAGE}.xml") end end @@ -46,7 +41,7 @@ before do allow(FileUtils).to receive(:mkdir_p) - .with(tika_test_config_path.join('ocr', described_class::VERSION)) + .with(tmp_tika_config_dir.join('ocr', described_class::VERSION)) .and_call_original end