From d2e5430d4a4f3828f5adbd7429752f9f11cfc07f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 24 May 2023 05:23:40 -0400 Subject: [PATCH] Fix RSpec/ExpectChange cop (#25101) --- .rubocop_todo.yml | 17 ----------------- .../account_moderation_notes_controller_spec.rb | 6 +++--- .../admin/custom_emojis_controller_spec.rb | 2 +- .../admin/invites_controller_spec.rb | 2 +- .../admin/report_notes_controller_spec.rb | 10 +++++----- .../concerns/accountable_concern_spec.rb | 2 +- spec/controllers/invites_controller_spec.rb | 2 +- .../webauthn_credentials_controller_spec.rb | 4 ++-- spec/models/admin/account_action_spec.rb | 2 +- spec/services/suspend_account_service_spec.rb | 2 +- spec/services/unsuspend_account_service_spec.rb | 6 +++--- .../accounts_statuses_cleanup_scheduler_spec.rb | 10 +++++----- 12 files changed, 24 insertions(+), 41 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2e9f6c429f..5711b3d4f2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -376,23 +376,6 @@ RSpec/EmptyExampleGroup: RSpec/ExampleLength: Max: 22 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: method_call, block -RSpec/ExpectChange: - Exclude: - - 'spec/controllers/admin/account_moderation_notes_controller_spec.rb' - - 'spec/controllers/admin/custom_emojis_controller_spec.rb' - - 'spec/controllers/admin/invites_controller_spec.rb' - - 'spec/controllers/admin/report_notes_controller_spec.rb' - - 'spec/controllers/concerns/accountable_concern_spec.rb' - - 'spec/controllers/invites_controller_spec.rb' - - 'spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb' - - 'spec/models/admin/account_action_spec.rb' - - 'spec/services/suspend_account_service_spec.rb' - - 'spec/services/unsuspend_account_service_spec.rb' - - 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, each, example diff --git a/spec/controllers/admin/account_moderation_notes_controller_spec.rb b/spec/controllers/admin/account_moderation_notes_controller_spec.rb index 848281c290..3e1b4b280f 100644 --- a/spec/controllers/admin/account_moderation_notes_controller_spec.rb +++ b/spec/controllers/admin/account_moderation_notes_controller_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Admin::AccountModerationNotesController do let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test content' } } } it 'successfully creates a note' do - expect { subject }.to change { AccountModerationNote.count }.by(1) + expect { subject }.to change(AccountModerationNote, :count).by(1) expect(subject).to redirect_to admin_account_path(target_account.id) end end @@ -28,7 +28,7 @@ RSpec.describe Admin::AccountModerationNotesController do let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } } it 'falls to create a note' do - expect { subject }.to_not change { AccountModerationNote.count } + expect { subject }.to_not change(AccountModerationNote, :count) expect(subject).to render_template 'admin/accounts/show' end end @@ -41,7 +41,7 @@ RSpec.describe Admin::AccountModerationNotesController do let(:account) { Fabricate(:account) } it 'destroys note' do - expect { subject }.to change { AccountModerationNote.count }.by(-1) + expect { subject }.to change(AccountModerationNote, :count).by(-1) expect(subject).to redirect_to admin_account_path(target_account.id) end end diff --git a/spec/controllers/admin/custom_emojis_controller_spec.rb b/spec/controllers/admin/custom_emojis_controller_spec.rb index d40691e1bf..6c32a3a579 100644 --- a/spec/controllers/admin/custom_emojis_controller_spec.rb +++ b/spec/controllers/admin/custom_emojis_controller_spec.rb @@ -42,7 +42,7 @@ describe Admin::CustomEmojisController do let(:params) { { shortcode: 'test', image: image } } it 'creates custom emoji' do - expect { subject }.to change { CustomEmoji.count }.by(1) + expect { subject }.to change(CustomEmoji, :count).by(1) end end diff --git a/spec/controllers/admin/invites_controller_spec.rb b/spec/controllers/admin/invites_controller_spec.rb index 92ec4e4491..ca87417305 100644 --- a/spec/controllers/admin/invites_controller_spec.rb +++ b/spec/controllers/admin/invites_controller_spec.rb @@ -26,7 +26,7 @@ describe Admin::InvitesController do subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } } it 'succeeds to create a invite' do - expect { subject }.to change { Invite.count }.by(1) + expect { subject }.to change(Invite, :count).by(1) expect(subject).to redirect_to admin_invites_path expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10) end diff --git a/spec/controllers/admin/report_notes_controller_spec.rb b/spec/controllers/admin/report_notes_controller_spec.rb index fb2fbd0588..b5ba4a84dc 100644 --- a/spec/controllers/admin/report_notes_controller_spec.rb +++ b/spec/controllers/admin/report_notes_controller_spec.rb @@ -25,7 +25,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } } it 'creates a report note and resolves report' do - expect { subject }.to change { ReportNote.count }.by(1) + expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to be_action_taken expect(subject).to redirect_to admin_reports_path end @@ -35,7 +35,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id } } } it 'creates a report note and does not resolve report' do - expect { subject }.to change { ReportNote.count }.by(1) + expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to_not be_action_taken expect(subject).to redirect_to admin_report_path(report) end @@ -50,7 +50,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } } it 'creates a report note and unresolves report' do - expect { subject }.to change { ReportNote.count }.by(1) + expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to_not be_action_taken expect(subject).to redirect_to admin_report_path(report) end @@ -60,7 +60,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id } } } it 'creates a report note and does not unresolve report' do - expect { subject }.to change { ReportNote.count }.by(1) + expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to be_action_taken expect(subject).to redirect_to admin_report_path(report) end @@ -85,7 +85,7 @@ describe Admin::ReportNotesController do let!(:report_note) { Fabricate(:report_note) } it 'deletes note' do - expect { subject }.to change { ReportNote.count }.by(-1) + expect { subject }.to change(ReportNote, :count).by(-1) expect(subject).to redirect_to admin_report_path(report_note.report) end end diff --git a/spec/controllers/concerns/accountable_concern_spec.rb b/spec/controllers/concerns/accountable_concern_spec.rb index 3c10082c34..cd06d872bb 100644 --- a/spec/controllers/concerns/accountable_concern_spec.rb +++ b/spec/controllers/concerns/accountable_concern_spec.rb @@ -22,7 +22,7 @@ RSpec.describe AccountableConcern do it 'creates Admin::ActionLog' do expect do hoge.log_action(:create, target) - end.to change { Admin::ActionLog.count }.by(1) + end.to change(Admin::ActionLog, :count).by(1) end end end diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index 8718403bf3..3190c82884 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -52,7 +52,7 @@ describe InvitesController do end it 'succeeds to create a invite' do - expect { subject }.to change { Invite.count }.by(1) + expect { subject }.to change(Invite, :count).by(1) expect(subject).to redirect_to invites_path expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10) end diff --git a/spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb b/spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb index 48dea62765..fe4868956c 100644 --- a/spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb +++ b/spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb @@ -134,7 +134,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do end it 'does not change webauthn_id' do - expect { get :options }.to_not change { user.webauthn_id } + expect { get :options }.to_not change(user, :webauthn_id) end it 'includes existing credentials in list of excluded credentials' do @@ -238,7 +238,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do expect do post :create, params: { credential: new_webauthn_credential, nickname: nickname } - end.to_not change { user.webauthn_id } + end.to_not change(user, :webauthn_id) end end diff --git a/spec/models/admin/account_action_spec.rb b/spec/models/admin/account_action_spec.rb index 442815c889..df79d9f287 100644 --- a/spec/models/admin/account_action_spec.rb +++ b/spec/models/admin/account_action_spec.rb @@ -58,7 +58,7 @@ RSpec.describe Admin::AccountAction do it 'creates Admin::ActionLog' do expect do subject - end.to change { Admin::ActionLog.count }.by 1 + end.to change(Admin::ActionLog, :count).by 1 end it 'calls process_email!' do diff --git a/spec/services/suspend_account_service_spec.rb b/spec/services/suspend_account_service_spec.rb index 4489bfed57..f9206b7ea2 100644 --- a/spec/services/suspend_account_service_spec.rb +++ b/spec/services/suspend_account_service_spec.rb @@ -26,7 +26,7 @@ RSpec.describe SuspendAccountService, type: :service do end it 'does not change the “suspended” flag' do - expect { subject }.to_not change { account.suspended? } + expect { subject }.to_not change(account, :suspended?) end end diff --git a/spec/services/unsuspend_account_service_spec.rb b/spec/services/unsuspend_account_service_spec.rb index 80285cc12b..e02ae41b99 100644 --- a/spec/services/unsuspend_account_service_spec.rb +++ b/spec/services/unsuspend_account_service_spec.rb @@ -33,7 +33,7 @@ RSpec.describe UnsuspendAccountService, type: :service do end it 'does not change the “suspended” flag' do - expect { subject }.to_not change { account.suspended? } + expect { subject }.to_not change(account, :suspended?) end include_examples 'with common context' do @@ -86,7 +86,7 @@ RSpec.describe UnsuspendAccountService, type: :service do end it 'does not change the “suspended” flag' do - expect { subject }.to_not change { account.suspended? } + expect { subject }.to_not change(account, :suspended?) end end @@ -110,7 +110,7 @@ RSpec.describe UnsuspendAccountService, type: :service do end it 'marks account as suspended' do - expect { subject }.to change { account.suspended? }.from(false).to(true) + expect { subject }.to change(account, :suspended?).from(false).to(true) end end diff --git a/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb b/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb index 8e747d04f5..fb626596fe 100644 --- a/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb +++ b/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb @@ -103,7 +103,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do describe '#perform' do context 'when the budget is lower than the number of toots to delete' do it 'deletes as many statuses as the given budget' do - expect { subject.perform }.to change { Status.count }.by(-subject.compute_budget) + expect { subject.perform }.to change(Status, :count).by(-subject.compute_budget) end it 'does not delete from accounts with no cleanup policy' do @@ -117,7 +117,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do it 'eventually deletes every deletable toot given enough runs' do stub_const 'Scheduler::AccountsStatusesCleanupScheduler::MAX_BUDGET', 4 - expect { 10.times { subject.perform } }.to change { Status.count }.by(-30) + expect { 10.times { subject.perform } }.to change(Status, :count).by(-30) end it 'correctly round-trips between users across several runs' do @@ -125,7 +125,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do stub_const 'Scheduler::AccountsStatusesCleanupScheduler::PER_ACCOUNT_BUDGET', 2 expect { 3.times { subject.perform } } - .to change { Status.count }.by(-3 * 3) + .to change(Status, :count).by(-3 * 3) .and change { account1.statuses.count } .and change { account3.statuses.count } .and change { account5.statuses.count } @@ -140,7 +140,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do it 'correctly handles looping in a single run' do expect(subject.compute_budget).to eq(400) - expect { subject.perform }.to change { Status.count }.by(-30) + expect { subject.perform }.to change(Status, :count).by(-30) end end @@ -154,7 +154,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do it 'does not get stuck' do expect(subject.compute_budget).to eq(400) - expect { subject.perform }.to_not change { Status.count } + expect { subject.perform }.to_not change(Status, :count) end end end