Reduce expectations for RSpec/MultipleExpectations cop in spec/presenters specs (#27881)

This commit is contained in:
Matt Jankowski 2023-11-16 09:37:52 -05:00 committed by GitHub
parent 155fb84141
commit cb1a4a8713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 32 deletions

View File

@ -23,12 +23,14 @@ RSpec.describe AccountRelationshipsPresenter do
let(:options) { {} }
it 'sets default maps' do
expect(presenter.following).to eq default_map
expect(presenter.followed_by).to eq default_map
expect(presenter.blocking).to eq default_map
expect(presenter.muting).to eq default_map
expect(presenter.requested).to eq default_map
expect(presenter.domain_blocking).to eq default_map
expect(presenter).to have_attributes(
following: default_map,
followed_by: default_map,
blocking: default_map,
muting: default_map,
requested: default_map,
domain_blocking: default_map
)
end
end

View File

@ -22,9 +22,12 @@ RSpec.describe FamiliarFollowersPresenter do
it 'returns followers you follow' do
result = subject.accounts.first
expect(result).to_not be_nil
expect(result.id).to eq requested_accounts.first.id
expect(result.accounts).to contain_exactly(familiar_follower)
expect(result)
.to be_present
.and have_attributes(
id: requested_accounts.first.id,
accounts: contain_exactly(familiar_follower)
)
end
context 'when requested account hides followers' do
@ -35,9 +38,12 @@ RSpec.describe FamiliarFollowersPresenter do
it 'does not return followers you follow' do
result = subject.accounts.first
expect(result).to_not be_nil
expect(result.id).to eq requested_accounts.first.id
expect(result.accounts).to be_empty
expect(result)
.to be_present
.and have_attributes(
id: requested_accounts.first.id,
accounts: be_empty
)
end
end
@ -49,9 +55,12 @@ RSpec.describe FamiliarFollowersPresenter do
it 'does not return followers you follow' do
result = subject.accounts.first
expect(result).to_not be_nil
expect(result.id).to eq requested_accounts.first.id
expect(result.accounts).to be_empty
expect(result)
.to be_present
.and have_attributes(
id: requested_accounts.first.id,
accounts: be_empty
)
end
end
end

View File

@ -22,11 +22,13 @@ RSpec.describe StatusRelationshipsPresenter do
let(:options) { {} }
it 'sets default maps' do
expect(presenter.reblogs_map).to eq default_map
expect(presenter.favourites_map).to eq default_map
expect(presenter.bookmarks_map).to eq default_map
expect(presenter.mutes_map).to eq default_map
expect(presenter.pins_map).to eq default_map
expect(presenter).to have_attributes(
reblogs_map: eq(default_map),
favourites_map: eq(default_map),
bookmarks_map: eq(default_map),
mutes_map: eq(default_map),
pins_map: eq(default_map)
)
end
end
@ -80,18 +82,30 @@ RSpec.describe StatusRelationshipsPresenter do
it 'sets @filters_map to filter top-level status' do
matched_filters = presenter.filters_map[statuses[0].id]
expect(matched_filters.size).to eq 1
expect(matched_filters[0].filter.title).to eq 'filter1'
expect(matched_filters[0].keyword_matches).to eq ['banned']
expect(matched_filters)
.to be_an(Array)
.and have_attributes(size: 1)
.and contain_exactly(
have_attributes(
filter: have_attributes(title: 'filter1'),
keyword_matches: contain_exactly('banned')
)
)
end
it 'sets @filters_map to filter reblogged status' do
matched_filters = presenter.filters_map[statuses[1].reblog_of_id]
expect(matched_filters.size).to eq 1
expect(matched_filters[0].filter.title).to eq 'filter1'
expect(matched_filters[0].keyword_matches).to eq ['irrelevant']
expect(matched_filters)
.to be_an(Array)
.and have_attributes(size: 1)
.and contain_exactly(
have_attributes(
filter: have_attributes(title: 'filter1'),
keyword_matches: contain_exactly('irrelevant')
)
)
end
end
@ -107,18 +121,30 @@ RSpec.describe StatusRelationshipsPresenter do
it 'sets @filters_map to filter top-level status' do
matched_filters = presenter.filters_map[statuses[0].id]
expect(matched_filters.size).to eq 1
expect(matched_filters[0].filter.title).to eq 'filter1'
expect(matched_filters[0].status_matches).to eq [statuses[0].id]
expect(matched_filters)
.to be_an(Array)
.and have_attributes(size: 1)
.and contain_exactly(
have_attributes(
filter: have_attributes(title: 'filter1'),
status_matches: contain_exactly(statuses.first.id)
)
)
end
it 'sets @filters_map to filter reblogged status' do
matched_filters = presenter.filters_map[statuses[1].reblog_of_id]
expect(matched_filters.size).to eq 1
expect(matched_filters[0].filter.title).to eq 'filter1'
expect(matched_filters[0].status_matches).to eq [statuses[1].reblog_of_id]
expect(matched_filters)
.to be_an(Array)
.and have_attributes(size: 1)
.and contain_exactly(
have_attributes(
filter: have_attributes(title: 'filter1'),
status_matches: contain_exactly(statuses.second.reblog_of_id)
)
)
end
end
end