From 6730232209d128caba5a81e7806e0243d913099c Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Fri, 27 Sep 2024 09:03:32 +0200 Subject: [PATCH] Improve specs - Add spec for #166 - Use `and_return` --- spec/integration/standard_tasks_spec.rb | 2 +- spec/lib/app_spec.rb | 2 +- spec/lib/colore/sidekiq/callback_worker_spec.rb | 2 +- spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb | 2 +- spec/lib/converter_spec.rb | 11 +++++++++-- spec/lib/legacy_converter_spec.rb | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spec/integration/standard_tasks_spec.rb b/spec/integration/standard_tasks_spec.rb index 4aa9b11..14d8e01 100644 --- a/spec/integration/standard_tasks_spec.rb +++ b/spec/integration/standard_tasks_spec.rb @@ -5,7 +5,7 @@ RSpec.describe 'Standard Heathen tasks:' do before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory) { tmp_storage_dir } + 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 c9cf546..8e3df79 100644 --- a/spec/lib/app_spec.rb +++ b/spec/lib/app_spec.rb @@ -29,7 +29,7 @@ def show_backtrace(response) before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory) { tmp_storage_dir } + 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 35c967b..bea37ea 100644 --- a/spec/lib/colore/sidekiq/callback_worker_spec.rb +++ b/spec/lib/colore/sidekiq/callback_worker_spec.rb @@ -10,7 +10,7 @@ before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory) { tmp_storage_dir } + 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 0a46949..8813a0f 100644 --- a/spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb +++ b/spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Colore::Sidekiq::LegacyPurgeWorker do before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory) { tmp_storage_dir } + 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 9be9cc0..a57c26a 100644 --- a/spec/lib/converter_spec.rb +++ b/spec/lib/converter_spec.rb @@ -11,11 +11,11 @@ let(:new_filename) { 'arglebargle.txt' } let(:converter) { described_class.new } let(:document) { Colore::Document.load storage_dir, doc_key } + let(:stubbed_converter) { instance_double(Heathen::Converter, convert: "The quick brown fox") } before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory) { tmp_storage_dir } - stubbed_converter = instance_double(Heathen::Converter, convert: "The quick brown fox") + allow(Colore::C_.config).to receive(:storage_directory).and_return(tmp_storage_dir) allow(Heathen::Converter).to receive(:new).and_return(stubbed_converter) end @@ -30,5 +30,12 @@ expect(content_type).to eq 'text/plain; charset=us-ascii' expect(content.to_s).to eq 'The quick brown fox' end + + context 'with Arabic language' do + it 'sets language to Heathen' do + converter.convert(doc_key, version, filename, action, 'ar') + expect(stubbed_converter).to have_received(:convert).with(action, an_instance_of(String), 'ar') + end + end end end diff --git a/spec/lib/legacy_converter_spec.rb b/spec/lib/legacy_converter_spec.rb index 1c73f0a..de57e25 100644 --- a/spec/lib/legacy_converter_spec.rb +++ b/spec/lib/legacy_converter_spec.rb @@ -10,7 +10,7 @@ before do setup_storage - allow(Colore::C_.config).to receive(:storage_directory) { tmp_storage_dir } + 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