Skip to content

Commit

Permalink
Fix RSpec/VerifiedDoubles cop (mastodon#25469)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored and skerit committed Jul 7, 2023
1 parent 2ede7f6 commit 55778c2
Show file tree
Hide file tree
Showing 50 changed files with 162 additions and 172 deletions.
39 changes: 0 additions & 39 deletions .rubocop_todo.yml
Expand Up @@ -437,45 +437,6 @@ RSpec/SubjectStub:
- 'spec/services/unallow_domain_service_spec.rb'
- 'spec/validators/blacklisted_email_validator_spec.rb'

# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/controllers/admin/change_emails_controller_spec.rb'
- 'spec/controllers/admin/confirmations_controller_spec.rb'
- 'spec/controllers/admin/disputes/appeals_controller_spec.rb'
- 'spec/controllers/admin/domain_allows_controller_spec.rb'
- 'spec/controllers/admin/domain_blocks_controller_spec.rb'
- 'spec/controllers/api/v1/reports_controller_spec.rb'
- 'spec/controllers/api/web/embeds_controller_spec.rb'
- 'spec/controllers/auth/sessions_controller_spec.rb'
- 'spec/controllers/disputes/appeals_controller_spec.rb'
- 'spec/helpers/statuses_helper_spec.rb'
- 'spec/lib/suspicious_sign_in_detector_spec.rb'
- 'spec/models/account/field_spec.rb'
- 'spec/models/session_activation_spec.rb'
- 'spec/models/setting_spec.rb'
- 'spec/services/account_search_service_spec.rb'
- 'spec/services/post_status_service_spec.rb'
- 'spec/services/search_service_spec.rb'
- 'spec/validators/blacklisted_email_validator_spec.rb'
- 'spec/validators/disallowed_hashtags_validator_spec.rb'
- 'spec/validators/email_mx_validator_spec.rb'
- 'spec/validators/follow_limit_validator_spec.rb'
- 'spec/validators/note_length_validator_spec.rb'
- 'spec/validators/poll_validator_spec.rb'
- 'spec/validators/status_length_validator_spec.rb'
- 'spec/validators/status_pin_validator_spec.rb'
- 'spec/validators/unique_username_validator_spec.rb'
- 'spec/validators/unreserved_username_validator_spec.rb'
- 'spec/validators/url_validator_spec.rb'
- 'spec/views/statuses/show.html.haml_spec.rb'
- 'spec/workers/activitypub/processing_worker_spec.rb'
- 'spec/workers/admin/domain_purge_worker_spec.rb'
- 'spec/workers/domain_block_worker_spec.rb'
- 'spec/workers/domain_clear_media_worker_spec.rb'
- 'spec/workers/feed_insert_worker_spec.rb'
- 'spec/workers/regeneration_worker_spec.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/ApplicationController:
Exclude:
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/admin/change_emails_controller_spec.rb
Expand Up @@ -23,7 +23,8 @@

describe 'GET #update' do
before do
allow(UserMailer).to receive(:confirmation_instructions).and_return(double('email', deliver_later: nil))
allow(UserMailer).to receive(:confirmation_instructions)
.and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
end

it 'returns http success' do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/confirmations_controller_spec.rb
Expand Up @@ -38,7 +38,7 @@
let!(:user) { Fabricate(:user, confirmed_at: confirmed_at) }

before do
allow(UserMailer).to receive(:confirmation_instructions) { double(:email, deliver_later: nil) }
allow(UserMailer).to receive(:confirmation_instructions) { instance_double(ActionMailer::MessageDelivery, deliver_later: nil) }
end

context 'when email is not confirmed' do
Expand Down
6 changes: 4 additions & 2 deletions spec/controllers/admin/disputes/appeals_controller_spec.rb
Expand Up @@ -19,7 +19,8 @@
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }

before do
allow(UserMailer).to receive(:appeal_approved).and_return(double('email', deliver_later: nil))
allow(UserMailer).to receive(:appeal_approved)
.and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
post :approve, params: { id: appeal.id }
end

Expand All @@ -40,7 +41,8 @@
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }

before do
allow(UserMailer).to receive(:appeal_rejected).and_return(double('email', deliver_later: nil))
allow(UserMailer).to receive(:appeal_rejected)
.and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
post :reject, params: { id: appeal.id }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/domain_allows_controller_spec.rb
Expand Up @@ -37,7 +37,7 @@

describe 'DELETE #destroy' do
it 'disallows the domain' do
service = double(call: true)
service = instance_double(UnallowDomainService, call: true)
allow(UnallowDomainService).to receive(:new).and_return(service)
domain_allow = Fabricate(:domain_allow)
delete :destroy, params: { id: domain_allow.id }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/domain_blocks_controller_spec.rb
Expand Up @@ -213,7 +213,7 @@

describe 'DELETE #destroy' do
it 'unblocks the domain' do
service = double(call: true)
service = instance_double(UnblockDomainService, call: true)
allow(UnblockDomainService).to receive(:new).and_return(service)
domain_block = Fabricate(:domain_block)
delete :destroy, params: { id: domain_block.id }
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/api/v1/reports_controller_spec.rb
Expand Up @@ -23,7 +23,8 @@
let(:rule_ids) { nil }

before do
allow(AdminMailer).to receive(:new_report).and_return(double('email', deliver_later: nil))
allow(AdminMailer).to receive(:new_report)
.and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
post :create, params: { status_ids: [status.id], account_id: target_account.id, comment: 'reasons', category: category, rule_ids: rule_ids, forward: forward }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/web/embeds_controller_spec.rb
Expand Up @@ -26,7 +26,7 @@

context 'when fails to find status' do
let(:url) { 'https://host.test/oembed.html' }
let(:service_instance) { double('fetch_oembed_service') }
let(:service_instance) { instance_double(FetchOEmbedService) }

before do
allow(FetchOEmbedService).to receive(:new) { service_instance }
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/auth/sessions_controller_spec.rb
Expand Up @@ -127,7 +127,8 @@

before do
allow_any_instance_of(ActionDispatch::Request).to receive(:remote_ip).and_return(current_ip)
allow(UserMailer).to receive(:suspicious_sign_in).and_return(double('email', deliver_later!: nil))
allow(UserMailer).to receive(:suspicious_sign_in)
.and_return(instance_double(ActionMailer::MessageDelivery, deliver_later!: nil))
user.update(current_sign_in_at: 1.month.ago)
post :create, params: { user: { email: user.email, password: user.password } }
end
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/authorize_interactions_controller_spec.rb
Expand Up @@ -28,7 +28,7 @@
end

it 'renders error when account cant be found' do
service = double
service = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(service)
allow(service).to receive(:call).with('missing@hostname').and_return(nil)

Expand All @@ -40,7 +40,7 @@

it 'sets resource from url' do
account = Fabricate(:account)
service = double
service = instance_double(ResolveURLService)
allow(ResolveURLService).to receive(:new).and_return(service)
allow(service).to receive(:call).with('http://example.com').and_return(account)

Expand All @@ -52,7 +52,7 @@

it 'sets resource from acct uri' do
account = Fabricate(:account)
service = double
service = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(service)
allow(service).to receive(:call).with('found@hostname').and_return(account)

Expand Down Expand Up @@ -82,7 +82,7 @@
end

it 'shows error when account not found' do
service = double
service = instance_double(ResolveAccountService)

allow(ResolveAccountService).to receive(:new).and_return(service)
allow(service).to receive(:call).with('user@hostname').and_return(nil)
Expand All @@ -94,7 +94,7 @@

it 'follows account when found' do
target_account = Fabricate(:account)
service = double
service = instance_double(ResolveAccountService)

allow(ResolveAccountService).to receive(:new).and_return(service)
allow(service).to receive(:call).with('user@hostname').and_return(target_account)
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/disputes/appeals_controller_spec.rb
Expand Up @@ -14,7 +14,8 @@
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }

before do
allow(AdminMailer).to receive(:new_appeal).and_return(double('email', deliver_later: nil))
allow(AdminMailer).to receive(:new_appeal)
.and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
post :create, params: { strike_id: strike.id, appeal: { text: 'Foo' } }
end

Expand Down
34 changes: 17 additions & 17 deletions spec/helpers/statuses_helper_spec.rb
Expand Up @@ -117,42 +117,42 @@ def set_embedded_view

describe '#style_classes' do
it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
classes = helper.style_classes(status, false, false, false)

expect(classes).to eq 'entry'
end

it do
status = double(reblog?: true)
status = instance_double(Status, reblog?: true)
classes = helper.style_classes(status, false, false, false)

expect(classes).to eq 'entry entry-reblog'
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
classes = helper.style_classes(status, true, false, false)

expect(classes).to eq 'entry entry-predecessor'
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
classes = helper.style_classes(status, false, true, false)

expect(classes).to eq 'entry entry-successor'
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
classes = helper.style_classes(status, false, false, true)

expect(classes).to eq 'entry entry-center'
end

it do
status = double(reblog?: true)
status = instance_double(Status, reblog?: true)
classes = helper.style_classes(status, true, true, true)

expect(classes).to eq 'entry entry-predecessor entry-reblog entry-successor entry-center'
Expand All @@ -161,35 +161,35 @@ def set_embedded_view

describe '#microformats_classes' do
it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
classes = helper.microformats_classes(status, false, false)

expect(classes).to eq ''
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
classes = helper.microformats_classes(status, true, false)

expect(classes).to eq 'p-in-reply-to'
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
classes = helper.microformats_classes(status, false, true)

expect(classes).to eq 'p-comment'
end

it do
status = double(reblog?: true)
status = instance_double(Status, reblog?: true)
classes = helper.microformats_classes(status, true, false)

expect(classes).to eq 'p-in-reply-to p-repost-of'
end

it do
status = double(reblog?: true)
status = instance_double(Status, reblog?: true)
classes = helper.microformats_classes(status, true, true)

expect(classes).to eq 'p-in-reply-to p-repost-of p-comment'
Expand All @@ -198,42 +198,42 @@ def set_embedded_view

describe '#microformats_h_class' do
it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
css_class = helper.microformats_h_class(status, false, false, false)

expect(css_class).to eq 'h-entry'
end

it do
status = double(reblog?: true)
status = instance_double(Status, reblog?: true)
css_class = helper.microformats_h_class(status, false, false, false)

expect(css_class).to eq 'h-cite'
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
css_class = helper.microformats_h_class(status, true, false, false)

expect(css_class).to eq 'h-cite'
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
css_class = helper.microformats_h_class(status, false, true, false)

expect(css_class).to eq 'h-cite'
end

it do
status = double(reblog?: false)
status = instance_double(Status, reblog?: false)
css_class = helper.microformats_h_class(status, false, false, true)

expect(css_class).to eq ''
end

it do
status = double(reblog?: true)
status = instance_double(Status, reblog?: true)
css_class = helper.microformats_h_class(status, true, true, true)

expect(css_class).to eq 'h-cite'
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/activitypub/activity/add_spec.rb
Expand Up @@ -26,7 +26,7 @@
end

context 'when status was not known before' do
let(:service_stub) { double }
let(:service_stub) { instance_double(ActivityPub::FetchRemoteStatusService) }

let(:json) do
{
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/activitypub/activity/move_spec.rb
Expand Up @@ -26,7 +26,7 @@
stub_request(:post, old_account.inbox_url).to_return(status: 200)
stub_request(:post, new_account.inbox_url).to_return(status: 200)

service_stub = double
service_stub = instance_double(ActivityPub::FetchRemoteAccountService)
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
allow(service_stub).to receive(:call).and_return(returned_account)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/request_spec.rb
Expand Up @@ -48,7 +48,7 @@
end

it 'executes a HTTP request when the first address is private' do
resolver = double
resolver = instance_double(Resolv::DNS)

allow(resolver).to receive(:getaddresses).with('example.com').and_return(%w(0.0.0.0 2001:4860:4860::8844))
allow(resolver).to receive(:timeouts=).and_return(nil)
Expand Down Expand Up @@ -83,7 +83,7 @@
end

it 'raises Mastodon::ValidationError' do
resolver = double
resolver = instance_double(Resolv::DNS)

allow(resolver).to receive(:getaddresses).with('example.com').and_return(%w(0.0.0.0 2001:db8::face))
allow(resolver).to receive(:timeouts=).and_return(nil)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/suspicious_sign_in_detector_spec.rb
Expand Up @@ -7,7 +7,7 @@
subject { described_class.new(user).suspicious?(request) }

let(:user) { Fabricate(:user, current_sign_in_at: 1.day.ago) }
let(:request) { double(remote_ip: remote_ip) }
let(:request) { instance_double(ActionDispatch::Request, remote_ip: remote_ip) }
let(:remote_ip) { nil }

context 'when user has 2FA enabled' do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/account/field_spec.rb
Expand Up @@ -6,7 +6,7 @@
describe '#verified?' do
subject { described_class.new(account, 'name' => 'Foo', 'value' => 'Bar', 'verified_at' => verified_at) }

let(:account) { double('Account', local?: true) }
let(:account) { instance_double(Account, local?: true) }

context 'when verified_at is set' do
let(:verified_at) { Time.now.utc.iso8601 }
Expand All @@ -28,7 +28,7 @@
describe '#mark_verified!' do
subject { described_class.new(account, original_hash) }

let(:account) { double('Account', local?: true) }
let(:account) { instance_double(Account, local?: true) }
let(:original_hash) { { 'name' => 'Foo', 'value' => 'Bar' } }

before do
Expand All @@ -47,7 +47,7 @@
describe '#verifiable?' do
subject { described_class.new(account, 'name' => 'Foo', 'value' => value) }

let(:account) { double('Account', local?: local) }
let(:account) { instance_double(Account, local?: local) }

context 'with local accounts' do
let(:local) { true }
Expand Down

0 comments on commit 55778c2

Please sign in to comment.