Skip to content

Commit 775407a

Browse files
committed
Doc and changelog updates
1 parent 2145388 commit 775407a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Master (Unreleased)
44

5+
- Update `RSpec/IteratedExpectation` cop documentation with an example of a matcher relying on block arguments. ([@jprince])
56
- Fix a false negative for `RSpec/ExcessiveDocstringSpacing` when finds description with em space. ([@ydah])
67

78
## 2.22.0 (2023-05-06)

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,26 @@ end
27102710
it 'validates users' do
27112711
expect([user1, user2, user3]).to all(be_valid)
27122712
end
2713+
2714+
# bad
2715+
it 'sets inferred fields for users' do
2716+
[user1, user2, user3].each do |user|
2717+
expect(user).to have_attributes(
2718+
post_count: PostService.new(user).post_count,
2719+
karma: KarmaService.new(user).value
2720+
)
2721+
end
2722+
end
2723+
2724+
# good
2725+
it 'sets inferred fields for users' do
2726+
expect([user1, user2, user3]).to all(satisfy do |user|
2727+
have_attributes(
2728+
post_count: PostService.new(user).post_count,
2729+
karma: KarmaService.new(user).value
2730+
)
2731+
end)
2732+
end
27132733
----
27142734

27152735
=== References

lib/rubocop/cop/rspec/iterated_expectation.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ module RSpec
1616
# expect([user1, user2, user3]).to all(be_valid)
1717
# end
1818
#
19+
# # bad
20+
# it 'sets inferred fields for users' do
21+
# [user1, user2, user3].each do |user|
22+
# expect(user).to have_attributes(
23+
# post_count: PostService.new(user).post_count,
24+
# karma: KarmaService.new(user).value
25+
# )
26+
# end
27+
# end
28+
#
29+
# # good
30+
# it 'sets inferred fields for users' do
31+
# expect([user1, user2, user3]).to all(satisfy do |user|
32+
# have_attributes(
33+
# post_count: PostService.new(user).post_count,
34+
# karma: KarmaService.new(user).value
35+
# )
36+
# end)
37+
# end
38+
#
1939
class IteratedExpectation < Base
2040
MSG = 'Prefer using the `all` matcher instead ' \
2141
'of iterating over an array.'

0 commit comments

Comments
 (0)