From 9e537435929a9f4e38fdb07a4db57e4e8afb0fb3 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Thu, 22 Jan 2026 18:32:08 -0800 Subject: [PATCH] test: stabilize mailer and signup validation specs --- .../shared/smtp_config_shared.rb | 10 ++++------ .../account/sign_up_email_validation_service_spec.rb | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/spec/mailers/administrator_notifications/shared/smtp_config_shared.rb b/spec/mailers/administrator_notifications/shared/smtp_config_shared.rb index 96d4dbb0d..0bb18a337 100644 --- a/spec/mailers/administrator_notifications/shared/smtp_config_shared.rb +++ b/spec/mailers/administrator_notifications/shared/smtp_config_shared.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true RSpec.shared_context 'with smtp config' do - before do - # We need to use allow_any_instance_of here because smtp_config_set_or_development? - # is defined in ApplicationMailer and needs to be stubbed for all mailer instances - # rubocop:disable RSpec/AnyInstance - allow_any_instance_of(ApplicationMailer).to receive(:smtp_config_set_or_development?).and_return(true) - # rubocop:enable RSpec/AnyInstance + around do |example| + # Set SMTP_ADDRESS so mailers build a Mail::Message in test without touching real SMTP. + # Scoped to this shared context to avoid affecting other specs. + with_modified_env('SMTP_ADDRESS' => 'smtp.example.com') { example.run } end end diff --git a/spec/services/account/sign_up_email_validation_service_spec.rb b/spec/services/account/sign_up_email_validation_service_spec.rb index 3f907f02c..a4b1231be 100644 --- a/spec/services/account/sign_up_email_validation_service_spec.rb +++ b/spec/services/account/sign_up_email_validation_service_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Account::SignUpEmailValidationService, type: :service do it 'raises InvalidEmail with invalid message' do allow(ValidEmail2::Address).to receive(:new).with(email).and_return(invalid_email_address) expect { service.perform }.to raise_error do |error| - expect(error).to be_a(CustomExceptions::Account::InvalidEmail) + expect(error.class.name).to eq('CustomExceptions::Account::InvalidEmail') expect(error.message).to eq(I18n.t('errors.signup.invalid_email')) end end @@ -32,7 +32,7 @@ RSpec.describe Account::SignUpEmailValidationService, type: :service do it 'raises InvalidEmail with blocked domain message' do allow(ValidEmail2::Address).to receive(:new).with(email).and_return(valid_email_address) expect { service.perform }.to raise_error do |error| - expect(error).to be_a(CustomExceptions::Account::InvalidEmail) + expect(error.class.name).to eq('CustomExceptions::Account::InvalidEmail') expect(error.message).to eq(I18n.t('errors.signup.blocked_domain')) end end @@ -44,7 +44,7 @@ RSpec.describe Account::SignUpEmailValidationService, type: :service do it 'raises InvalidEmail with blocked domain message' do allow(ValidEmail2::Address).to receive(:new).with(email).and_return(valid_email_address) expect { service.perform }.to raise_error do |error| - expect(error).to be_a(CustomExceptions::Account::InvalidEmail) + expect(error.class.name).to eq('CustomExceptions::Account::InvalidEmail') expect(error.message).to eq(I18n.t('errors.signup.blocked_domain')) end end @@ -56,7 +56,7 @@ RSpec.describe Account::SignUpEmailValidationService, type: :service do it 'raises InvalidEmail with disposable message' do allow(ValidEmail2::Address).to receive(:new).with(email).and_return(disposable_email_address) expect { service.perform }.to raise_error do |error| - expect(error).to be_a(CustomExceptions::Account::InvalidEmail) + expect(error.class.name).to eq('CustomExceptions::Account::InvalidEmail') expect(error.message).to eq(I18n.t('errors.signup.disposable_email')) end end