Skip to content

Commit

Permalink
Reduce expectations for RSpec/MultipleExpectations cop in `spec/pre…
Browse files Browse the repository at this point in the history
…senters` specs (mastodon#27881)
  • Loading branch information
mjankowski authored and vmstan committed Jan 5, 2024
1 parent 761d2e5 commit 28a05d8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 32 deletions.
14 changes: 8 additions & 6 deletions spec/presenters/account_relationships_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
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

Expand Down
27 changes: 18 additions & 9 deletions spec/presenters/familiar_followers_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
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
Expand All @@ -35,9 +38,12 @@
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

Expand All @@ -49,9 +55,12 @@
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
Expand Down
60 changes: 43 additions & 17 deletions spec/presenters/status_relationships_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
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

Expand Down Expand Up @@ -80,18 +82,30 @@

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

Expand All @@ -107,18 +121,30 @@

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

0 comments on commit 28a05d8

Please sign in to comment.