diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2021-03-28 10:37:16 +0200 |
---|---|---|
committer | Alessandro Desantis <desa.alessandro@gmail.com> | 2021-03-28 10:42:39 +0200 |
commit | c3154c77bf904526d778953b9ee235ac9c62e4ef (patch) | |
tree | 2c9c15039226e7a3c1f86c7b035d379886ab281f /spec/jobs | |
parent | 7559ec52ced8ab0894ba2f3159036c4450477116 (diff) |
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.
Diffstat (limited to 'spec/jobs')
-rw-r--r-- | spec/jobs/solidus_subscriptions/process_installment_job_spec.rb | 17 |
1 files 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 |