Skip to content

Commit 99884b1

Browse files
committed
[Fix #1184] false positive when block do not have child nodes
1 parent 2ff7294 commit 99884b1

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
* Exclude unrelated Rails directories from `RSpec/DescribeClass`. ([@MothOnMars][])
88
* Add `RSpec/ExcessiveDocstringSpacing` cop. ([@G-Rath][])
99
* Add `RSpec/SubjectDeclaration` cop. ([@dswij][])
10-
* Fix excessive whitespace removal in `RSpec/EmptyHook' autocorrection. ([@pirj][])
10+
* Fix excessive whitespace removal in `RSpec/EmptyHook` autocorrection. ([@pirj][])
1111
* Bump RuboCop requirement to v1.19.0. ([@pirj][])
12+
* Fix false positive in `RSpec/IteratedExpectation` when there is single, non-espectation statement in the block body. ([@Darhazer][])
1213

1314
## 2.4.0 (2021-06-09)
1415

lib/rubocop/cop/rspec/iterated_expectation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def single_expectation?(body, arg)
4848
end
4949

5050
def only_expectations?(body, arg)
51+
return false unless body.each_child_node.any?
52+
5153
body.each_child_node.all? { |child| expectation?(child, arg) }
5254
end
5355
end

spec/rubocop/cop/rspec/iterated_expectation_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
RUBY
2828
end
2929

30+
it 'ignores `each` with unused variable' do
31+
expect_no_offenses(<<-RUBY)
32+
it 'validates users' do
33+
[user1, user2, user3].each { |_user| do_something }
34+
end
35+
RUBY
36+
end
37+
3038
it 'flags `each` with multiple expectations' do
3139
expect_offense(<<-RUBY)
3240
it 'validates users' do

0 commit comments

Comments
 (0)