0
0
Fork 0

Fix RSpec/MessageSpies cop (#27751)

This commit is contained in:
Matt Jankowski 2023-11-07 04:46:28 -05:00 committed by GitHub
parent ae0d551d33
commit 49e2772064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 162 additions and 94 deletions

View file

@ -78,13 +78,15 @@ RSpec.describe Admin::AccountAction do
end
it 'calls process_email!' do
expect(account_action).to receive(:process_email!)
allow(account_action).to receive(:process_email!)
subject
expect(account_action).to have_received(:process_email!)
end
it 'calls process_reports!' do
expect(account_action).to receive(:process_reports!)
allow(account_action).to receive(:process_reports!)
subject
expect(account_action).to have_received(:process_reports!)
end
end

View file

@ -120,8 +120,11 @@ RSpec.describe Remotable do
end
it 'does not try to write attribute' do
expect(foo).to_not receive('[]=').with(attribute_name, url)
allow(foo).to receive('[]=').with(attribute_name, url)
foo.hoge_remote_url = url
expect(foo).to_not have_received('[]=').with(attribute_name, url)
end
end
@ -131,8 +134,11 @@ RSpec.describe Remotable do
end
it 'does not try to write attribute' do
expect(foo).to receive('[]=').with(attribute_name, url)
allow(foo).to receive('[]=').with(attribute_name, url)
foo.hoge_remote_url = url
expect(foo).to have_received('[]=').with(attribute_name, url)
end
end
@ -146,10 +152,13 @@ RSpec.describe Remotable do
let(:code) { 500 }
it 'does not assign file' do
expect(foo).to_not receive(:public_send).with("#{hoge}=", any_args)
expect(foo).to_not receive(:public_send).with("#{hoge}_file_name=", any_args)
allow(foo).to receive(:public_send)
allow(foo).to receive(:public_send)
foo.hoge_remote_url = url
expect(foo).to_not have_received(:public_send).with("#{hoge}=", any_args)
expect(foo).to_not have_received(:public_send).with("#{hoge}_file_name=", any_args)
end
end
@ -165,13 +174,13 @@ RSpec.describe Remotable do
allow(ResponseWithLimit).to receive(:new).with(anything, anything).and_return(response_with_limit)
expect(foo).to receive(:public_send).with("download_#{hoge}!", url)
allow(foo).to receive(:public_send)
foo.hoge_remote_url = url
expect(foo).to have_received(:public_send).with("download_#{hoge}!", url)
expect(foo).to receive(:public_send).with("#{hoge}=", response_with_limit)
allow(foo).to receive(:public_send)
foo.download_hoge!(url)
expect(foo).to have_received(:public_send).with("#{hoge}=", response_with_limit)
end
end
end
@ -193,10 +202,13 @@ RSpec.describe Remotable do
let(:error_class) { error_class }
it 'calls Rails.logger.debug' do
expect(Rails.logger).to receive(:debug) do |&block|
allow(Rails.logger).to receive(:debug)
foo.hoge_remote_url = url
expect(Rails.logger).to have_received(:debug) do |&block|
expect(block.call).to match(/^Error fetching remote #{hoge}: /)
end
foo.hoge_remote_url = url
end
end
end

View file

@ -21,12 +21,17 @@ RSpec.describe FollowRequest do
end
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true) do
allow(account).to receive(:follow!) do
account.active_relationships.create!(target_account: target_account)
end
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
expect(follow_request).to receive(:destroy!)
allow(MergeWorker).to receive(:perform_async)
allow(follow_request).to receive(:destroy!)
follow_request.authorize!
expect(account).to have_received(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true)
expect(MergeWorker).to have_received(:perform_async).with(target_account.id, account.id)
expect(follow_request).to have_received(:destroy!)
end
it 'correctly passes show_reblogs when true' do

View file

@ -7,8 +7,11 @@ RSpec.describe Identity do
let(:auth) { Fabricate(:identity, user: Fabricate(:user)) }
it 'calls .find_or_create_by' do
expect(described_class).to receive(:find_or_create_by).with(uid: auth.uid, provider: auth.provider)
allow(described_class).to receive(:find_or_create_by)
described_class.find_for_oauth(auth)
expect(described_class).to have_received(:find_or_create_by).with(uid: auth.uid, provider: auth.provider)
end
it 'returns an instance of Identity' do

View file

@ -74,9 +74,13 @@ RSpec.describe SessionActivation do
let(:options) { { user: Fabricate(:user), session_id: '1' } }
it 'calls create! and purge_old' do
expect(described_class).to receive(:create!).with(**options)
expect(described_class).to receive(:purge_old)
allow(described_class).to receive(:create!).with(**options)
allow(described_class).to receive(:purge_old)
described_class.activate(**options)
expect(described_class).to have_received(:create!).with(**options)
expect(described_class).to have_received(:purge_old)
end
it 'returns an instance of SessionActivation' do

View file

@ -23,8 +23,11 @@ RSpec.describe Setting do
let(:rails_initialized) { false }
it 'calls RailsSettings::Base#[]' do
expect(RailsSettings::Base).to receive(:[]).with(key)
allow(RailsSettings::Base).to receive(:[]).with(key)
described_class[key]
expect(RailsSettings::Base).to have_received(:[]).with(key)
end
end
@ -38,8 +41,11 @@ RSpec.describe Setting do
let(:cache_value) { 'cache-value' }
it 'calls not RailsSettings::Base#[]' do
expect(RailsSettings::Base).to_not receive(:[]).with(key)
allow(RailsSettings::Base).to receive(:[]).with(key)
described_class[key]
expect(RailsSettings::Base).to_not have_received(:[]).with(key)
end
context 'when Rails.cache does not exists' do
@ -56,8 +62,11 @@ RSpec.describe Setting do
let(:records) { [Fabricate(:setting, var: key, value: nil)] }
it 'calls RailsSettings::Settings.object' do
expect(RailsSettings::Settings).to receive(:object).with(key)
allow(RailsSettings::Settings).to receive(:object).with(key)
described_class[key]
expect(RailsSettings::Settings).to have_received(:object).with(key)
end
context 'when RailsSettings::Settings.object returns truthy' do