From c3154c77bf904526d778953b9ee235ac9c62e4ef Mon Sep 17 00:00:00 2001 From: Alessandro Desantis Date: Sun, 28 Mar 2021 10:37:16 +0200 Subject: Fix overly specific not_to raise_error RSpec expectation not_to raise_error should never be ued with specific error classes, since any other error would make the test pass, including the ones raised by Ruby, meaning that the code being tested may never be reached. --- .../process_installment_job_spec.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb index 658e252..bc33d0e 100644 --- a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb +++ b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb @@ -13,13 +13,26 @@ RSpec.describe SolidusSubscriptions::ProcessInstallmentJob do context 'when handling #perform errors' do it 'swallows error when a proc is not configured' do - expect { described_class.perform_now(nil) }.not_to raise_error(StandardError) + checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c| + allow(c).to receive(:process).and_raise('test error') + end + allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout) + + expect { + described_class.perform_now(build_stubbed(:installment)) + }.not_to raise_error end it 'runs proc when a proc is configured' do stub_config(processing_error_handler: proc { |e| raise e } ) + checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c| + allow(c).to receive(:process).and_raise('test error') + end + allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout) - expect { described_class.perform_now(nil) }.to raise_error(StandardError) + expect { + described_class.perform_now(build_stubbed(:installment)) + }.to raise_error(/test error/) end end end -- cgit v1.2.3