Skip to content

Commit

Permalink
Merge pull request #320 from ifad/chore/improve-specs
Browse files Browse the repository at this point in the history
Improve storage and tika spec helpers
  • Loading branch information
tagliala authored Sep 27, 2024
2 parents 8dce844 + c20ef51 commit f4ebc97
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 16 deletions.
2 changes: 2 additions & 0 deletions spec/helpers/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/helpers/tika_config.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion spec/integration/standard_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/lib/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion spec/lib/colore/sidekiq/callback_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

before do
setup_storage
allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir)
end

after do
Expand Down
1 change: 0 additions & 1 deletion spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion spec/lib/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion spec/lib/legacy_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions spec/lib/tika_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,15 +24,15 @@
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

context 'when the language is not found' do
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

Expand All @@ -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

Expand Down

0 comments on commit f4ebc97

Please sign in to comment.