Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RSpec/ExpectChange cop #25101

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 0 additions & 17 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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
Expand All @@ -28,7 +28,7 @@
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
Expand All @@ -41,7 +41,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/custom_emojis_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/invites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/admin/report_notes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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
Expand All @@ -35,7 +35,7 @@
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
Expand All @@ -50,7 +50,7 @@
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
Expand All @@ -60,7 +60,7 @@
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
Expand All @@ -85,7 +85,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/concerns/accountable_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(current_account)
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
2 changes: 1 addition & 1 deletion spec/controllers/invites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def add_webauthn_credential(user)
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
Expand Down Expand Up @@ -238,7 +238,7 @@ def add_webauthn_credential(user)

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

Expand Down
2 changes: 1 addition & 1 deletion spec/models/admin/account_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/services/suspend_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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

Expand Down
6 changes: 3 additions & 3 deletions spec/services/unsuspend_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def match_update_actor_request(req, account)
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
Expand Down Expand Up @@ -86,7 +86,7 @@ def match_update_actor_request(req, account)
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

Expand All @@ -110,7 +110,7 @@ def match_update_actor_request(req, account)
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
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
Expand All @@ -117,15 +117,15 @@
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
stub_const 'Scheduler::AccountsStatusesCleanupScheduler::MAX_BUDGET', 3
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 }
Expand All @@ -140,7 +140,7 @@

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

Expand All @@ -154,7 +154,7 @@

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
Expand Down