Skip to content

Commit

Permalink
Merge branch 'master' into fix/1669
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jul 17, 2023
2 parents 0fb71b9 + 003e208 commit 31c7ca3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix a false negative for `RSpec/Pending` when `it` without body. ([@ydah])
- Add new `RSpec/ReceiveMessages` cop. ([@ydah])
- Add `AllowedIdentifiers` and `AllowedPatterns` configuration option to `RSpec/IndexedLet`. ([@ydah])
- Fix `RSpec/NamedSubject` when block has no body. ([@splattael])
- Fix `RSpec/LetBeforeExamples` autocorrect incompatible with `RSpec/ScatteredLet` autocorrect. ([@ydah])

## 2.22.0 (2023-05-06)
Expand Down Expand Up @@ -868,6 +869,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@seanpdoyle]: https://github.com/seanpdoyle
[@sl4vr]: https://github.com/sl4vr
[@smcgivern]: https://github.com/smcgivern
[@splattael]: https://github.com/splattael
[@stephannv]: https://github.com/stephannv
[@t3h2mas]: https://github.com/t3h2mas
[@tdeo]: https://github.com/tdeo
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/named_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def nearest_subject(node)
end

def find_subject(block_node)
block_node.body.child_nodes.find { |send_node| subject?(send_node) }
block_node.body&.child_nodes&.find { |send_node| subject?(send_node) }
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/rspec/named_subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ def foo
end
RUBY
end

it 'ignores subject when block has no body' do
expect_no_offenses(<<-RUBY)
it "is a User" do
subject.each do
# empty body
end
end
RUBY
end
end

context 'when IgnoreSharedExamples is false' do
Expand Down

0 comments on commit 31c7ca3

Please sign in to comment.