From 74806deb2c1d135b3454d4e222ede8fa5a637ed0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 12 Jul 2023 04:02:19 -0400 Subject: [PATCH] Fix `RSpec/SubjectStub` cop (#25550) Co-authored-by: Claire --- .rubocop_todo.yml | 5 ----- spec/services/unallow_domain_service_spec.rb | 4 ++-- spec/validators/blacklisted_email_validator_spec.rb | 11 +++++++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9938916fc..7ec4e35f7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -409,11 +409,6 @@ RSpec/StubbedMock: - 'spec/lib/webfinger_resource_spec.rb' - 'spec/services/activitypub/process_collection_service_spec.rb' -RSpec/SubjectStub: - Exclude: - - 'spec/services/unallow_domain_service_spec.rb' - - 'spec/validators/blacklisted_email_validator_spec.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Rails/ApplicationController: Exclude: diff --git a/spec/services/unallow_domain_service_spec.rb b/spec/services/unallow_domain_service_spec.rb index e583a22de..f27b6fdf3 100644 --- a/spec/services/unallow_domain_service_spec.rb +++ b/spec/services/unallow_domain_service_spec.rb @@ -14,7 +14,7 @@ RSpec.describe UnallowDomainService, type: :service do context 'with limited federation mode' do before do - allow(subject).to receive(:whitelist_mode?).and_return(true) + allow(Rails.configuration.x).to receive(:whitelist_mode).and_return(true) end describe '#call' do @@ -40,7 +40,7 @@ RSpec.describe UnallowDomainService, type: :service do context 'without limited federation mode' do before do - allow(subject).to receive(:whitelist_mode?).and_return(false) + allow(Rails.configuration.x).to receive(:whitelist_mode).and_return(false) end describe '#call' do diff --git a/spec/validators/blacklisted_email_validator_spec.rb b/spec/validators/blacklisted_email_validator_spec.rb index 3d3d50f65..bfe2a11a9 100644 --- a/spec/validators/blacklisted_email_validator_spec.rb +++ b/spec/validators/blacklisted_email_validator_spec.rb @@ -11,14 +11,15 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do before do allow(user).to receive(:valid_invitation?).and_return(false) - allow_any_instance_of(described_class).to receive(:blocked_email_provider?) { blocked_email } + allow(EmailDomainBlock).to receive(:block?) { blocked_email } end context 'when e-mail provider is blocked' do let(:blocked_email) { true } it 'adds error' do - expect(subject).to have_received(:add).with(:email, :blocked) + described_class.new.validate(user) + expect(errors).to have_received(:add).with(:email, :blocked).once end end @@ -26,7 +27,8 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do let(:blocked_email) { false } it 'does not add errors' do - expect(subject).to_not have_received(:add).with(:email, :blocked) + described_class.new.validate(user) + expect(errors).to_not have_received(:add) end context 'when canonical e-mail is blocked' do @@ -37,7 +39,8 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do end it 'adds error' do - expect(subject).to have_received(:add).with(:email, :taken) + described_class.new.validate(user) + expect(errors).to have_received(:add).with(:email, :taken).once end end end