Fix RSpec/VerifiedDoubles cop (#25469)

This commit is contained in:
Matt Jankowski
2023-06-22 08:55:22 -04:00
committed by GitHub
parent 38433ccd0b
commit 05f9e39b32
50 changed files with 162 additions and 172 deletions

View File

@ -53,7 +53,7 @@ describe AccountSearchService, type: :service do
context 'when there is a domain but no exact match' do
it 'follows the remote account when resolve is true' do
service = double(call: nil)
service = instance_double(ResolveAccountService, call: nil)
allow(ResolveAccountService).to receive(:new).and_return(service)
results = subject.call('newuser@remote.com', nil, limit: 10, resolve: true)
@ -61,7 +61,7 @@ describe AccountSearchService, type: :service do
end
it 'does not follow the remote account when resolve is false' do
service = double(call: nil)
service = instance_double(ResolveAccountService, call: nil)
allow(ResolveAccountService).to receive(:new).and_return(service)
results = subject.call('newuser@remote.com', nil, limit: 10, resolve: false)

View File

@ -6,7 +6,7 @@ RSpec.describe BootstrapTimelineService, type: :service do
subject { described_class.new }
context 'when the new user has registered from an invite' do
let(:service) { double }
let(:service) { instance_double(FollowService) }
let(:autofollow) { false }
let(:inviter) { Fabricate(:user, confirmed_at: 2.days.ago) }
let(:invite) { Fabricate(:invite, user: inviter, max_uses: nil, expires_at: 1.hour.from_now, autofollow: autofollow) }

View File

@ -47,7 +47,7 @@ RSpec.describe BulkImportService do
it 'requests to follow all the listed users once the workers have run' do
subject.call(import)
resolve_account_service_double = double
resolve_account_service_double = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service_double)
allow(resolve_account_service_double).to receive(:call).with('user@foo.bar', any_args) { Fabricate(:account, username: 'user', domain: 'foo.bar', protocol: :activitypub) }
allow(resolve_account_service_double).to receive(:call).with('unknown@unknown.bar', any_args) { Fabricate(:account, username: 'unknown', domain: 'unknown.bar', protocol: :activitypub) }
@ -95,7 +95,7 @@ RSpec.describe BulkImportService do
it 'requests to follow all the expected users once the workers have run' do
subject.call(import)
resolve_account_service_double = double
resolve_account_service_double = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service_double)
allow(resolve_account_service_double).to receive(:call).with('user@foo.bar', any_args) { Fabricate(:account, username: 'user', domain: 'foo.bar', protocol: :activitypub) }
allow(resolve_account_service_double).to receive(:call).with('unknown@unknown.bar', any_args) { Fabricate(:account, username: 'unknown', domain: 'unknown.bar', protocol: :activitypub) }
@ -133,7 +133,7 @@ RSpec.describe BulkImportService do
it 'blocks all the listed users once the workers have run' do
subject.call(import)
resolve_account_service_double = double
resolve_account_service_double = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service_double)
allow(resolve_account_service_double).to receive(:call).with('user@foo.bar', any_args) { Fabricate(:account, username: 'user', domain: 'foo.bar', protocol: :activitypub) }
allow(resolve_account_service_double).to receive(:call).with('unknown@unknown.bar', any_args) { Fabricate(:account, username: 'unknown', domain: 'unknown.bar', protocol: :activitypub) }
@ -177,7 +177,7 @@ RSpec.describe BulkImportService do
it 'requests to follow all the expected users once the workers have run' do
subject.call(import)
resolve_account_service_double = double
resolve_account_service_double = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service_double)
allow(resolve_account_service_double).to receive(:call).with('user@foo.bar', any_args) { Fabricate(:account, username: 'user', domain: 'foo.bar', protocol: :activitypub) }
allow(resolve_account_service_double).to receive(:call).with('unknown@unknown.bar', any_args) { Fabricate(:account, username: 'unknown', domain: 'unknown.bar', protocol: :activitypub) }
@ -215,7 +215,7 @@ RSpec.describe BulkImportService do
it 'mutes all the listed users once the workers have run' do
subject.call(import)
resolve_account_service_double = double
resolve_account_service_double = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service_double)
allow(resolve_account_service_double).to receive(:call).with('user@foo.bar', any_args) { Fabricate(:account, username: 'user', domain: 'foo.bar', protocol: :activitypub) }
allow(resolve_account_service_double).to receive(:call).with('unknown@unknown.bar', any_args) { Fabricate(:account, username: 'unknown', domain: 'unknown.bar', protocol: :activitypub) }
@ -263,7 +263,7 @@ RSpec.describe BulkImportService do
it 'requests to follow all the expected users once the workers have run' do
subject.call(import)
resolve_account_service_double = double
resolve_account_service_double = instance_double(ResolveAccountService)
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service_double)
allow(resolve_account_service_double).to receive(:call).with('user@foo.bar', any_args) { Fabricate(:account, username: 'user', domain: 'foo.bar', protocol: :activitypub) }
allow(resolve_account_service_double).to receive(:call).with('unknown@unknown.bar', any_args) { Fabricate(:account, username: 'unknown', domain: 'unknown.bar', protocol: :activitypub) }
@ -360,7 +360,7 @@ RSpec.describe BulkImportService do
it 'updates the bookmarks as expected once the workers have run' do
subject.call(import)
service_double = double
service_double = instance_double(ActivityPub::FetchRemoteStatusService)
allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service_double)
allow(service_double).to receive(:call).with('https://domain.unknown/foo') { Fabricate(:status, uri: 'https://domain.unknown/foo') }
allow(service_double).to receive(:call).with('https://domain.unknown/private') { Fabricate(:status, uri: 'https://domain.unknown/private', visibility: :direct) }
@ -403,7 +403,7 @@ RSpec.describe BulkImportService do
it 'updates the bookmarks as expected once the workers have run' do
subject.call(import)
service_double = double
service_double = instance_double(ActivityPub::FetchRemoteStatusService)
allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service_double)
allow(service_double).to receive(:call).with('https://domain.unknown/foo') { Fabricate(:status, uri: 'https://domain.unknown/foo') }
allow(service_double).to receive(:call).with('https://domain.unknown/private') { Fabricate(:status, uri: 'https://domain.unknown/private', visibility: :direct) }

View File

@ -24,7 +24,7 @@ RSpec.describe FetchResourceService, type: :service do
context 'when OpenSSL::SSL::SSLError is raised' do
before do
request = double
request = instance_double(Request)
allow(Request).to receive(:new).and_return(request)
allow(request).to receive(:add_headers)
allow(request).to receive(:on_behalf_of)
@ -36,7 +36,7 @@ RSpec.describe FetchResourceService, type: :service do
context 'when HTTP::ConnectionError is raised' do
before do
request = double
request = instance_double(Request)
allow(Request).to receive(:new).and_return(request)
allow(request).to receive(:add_headers)
allow(request).to receive(:on_behalf_of)

View File

@ -219,7 +219,7 @@ RSpec.describe ImportService, type: :service do
end
before do
service = double
service = instance_double(ActivityPub::FetchRemoteStatusService)
allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service)
allow(service).to receive(:call).with('https://unknown-remote.com/users/bar/statuses/1') do
Fabricate(:status, uri: 'https://unknown-remote.com/users/bar/statuses/1')

View File

@ -132,7 +132,7 @@ RSpec.describe PostStatusService, type: :service do
end
it 'processes mentions' do
mention_service = double(:process_mentions_service)
mention_service = instance_double(ProcessMentionsService)
allow(mention_service).to receive(:call)
allow(ProcessMentionsService).to receive(:new).and_return(mention_service)
account = Fabricate(:account)
@ -163,7 +163,7 @@ RSpec.describe PostStatusService, type: :service do
end
it 'processes hashtags' do
hashtags_service = double(:process_hashtags_service)
hashtags_service = instance_double(ProcessHashtagsService)
allow(hashtags_service).to receive(:call)
allow(ProcessHashtagsService).to receive(:new).and_return(hashtags_service)
account = Fabricate(:account)

View File

@ -9,7 +9,7 @@ describe ResolveURLService, type: :service do
it 'returns nil when there is no resource url' do
url = 'http://example.com/missing-resource'
known_account = Fabricate(:account, uri: url)
service = double
service = instance_double(FetchResourceService)
allow(FetchResourceService).to receive(:new).and_return service
allow(service).to receive(:response_code).and_return(404)
@ -21,7 +21,7 @@ describe ResolveURLService, type: :service do
it 'returns known account on temporary error' do
url = 'http://example.com/missing-resource'
known_account = Fabricate(:account, uri: url)
service = double
service = instance_double(FetchResourceService)
allow(FetchResourceService).to receive(:new).and_return service
allow(service).to receive(:response_code).and_return(500)

View File

@ -25,7 +25,7 @@ describe SearchService, type: :service do
context 'when it does not find anything' do
it 'returns the empty results' do
service = double(call: nil)
service = instance_double(ResolveURLService, call: nil)
allow(ResolveURLService).to receive(:new).and_return(service)
results = subject.call(@query, nil, 10, resolve: true)
@ -37,7 +37,7 @@ describe SearchService, type: :service do
context 'when it finds an account' do
it 'includes the account in the results' do
account = Account.new
service = double(call: account)
service = instance_double(ResolveURLService, call: account)
allow(ResolveURLService).to receive(:new).and_return(service)
results = subject.call(@query, nil, 10, resolve: true)
@ -49,7 +49,7 @@ describe SearchService, type: :service do
context 'when it finds a status' do
it 'includes the status in the results' do
status = Status.new
service = double(call: status)
service = instance_double(ResolveURLService, call: status)
allow(ResolveURLService).to receive(:new).and_return(service)
results = subject.call(@query, nil, 10, resolve: true)
@ -64,7 +64,7 @@ describe SearchService, type: :service do
it 'includes the account in the results' do
query = 'username'
account = Account.new
service = double(call: [account])
service = instance_double(AccountSearchService, call: [account])
allow(AccountSearchService).to receive(:new).and_return(service)
results = subject.call(query, nil, 10)

View File

@ -63,7 +63,7 @@ RSpec.describe UnsuspendAccountService, type: :service do
describe 'unsuspending a remote account' do
include_examples 'with common context' do
let!(:account) { Fabricate(:account, domain: 'bob.com', uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
let!(:resolve_account_service) { double }
let!(:resolve_account_service) { instance_double(ResolveAccountService) }
before do
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service)