Skip to content

Commit

Permalink
Doc and changelog updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jprince authored and ydah committed Jun 12, 2023
1 parent 2145388 commit de6435d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,26 @@ end
it 'validates users' do
expect([user1, user2, user3]).to all(be_valid)
end
# bad
it 'sets inferred fields for users' do
[user1, user2, user3].each do |user|
expect(user).to have_attributes(
post_count: PostService.new(user).post_count,
karma: KarmaService.new(user).value
)
end
end
# good
it 'sets inferred fields for users' do
expect([user1, user2, user3]).to all(satisfy do |user|
have_attributes(
post_count: PostService.new(user).post_count,
karma: KarmaService.new(user).value
)
end)
end
----

=== References
Expand Down
20 changes: 20 additions & 0 deletions lib/rubocop/cop/rspec/iterated_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ module RSpec
# expect([user1, user2, user3]).to all(be_valid)
# end
#
# # bad
# it 'sets inferred fields for users' do
# [user1, user2, user3].each do |user|
# expect(user).to have_attributes(
# post_count: PostService.new(user).post_count,
# karma: KarmaService.new(user).value
# )
# end
# end
#
# # good
# it 'sets inferred fields for users' do
# expect([user1, user2, user3]).to all(satisfy do |user|
# have_attributes(
# post_count: PostService.new(user).post_count,
# karma: KarmaService.new(user).value
# )
# end)
# end
#
class IteratedExpectation < Base
MSG = 'Prefer using the `all` matcher instead ' \
'of iterating over an array.'
Expand Down

0 comments on commit de6435d

Please sign in to comment.