Skip to content

Commit

Permalink
Fix RSpec/ScatteredLet to detect let with proc argument
Browse files Browse the repository at this point in the history
Closes #771
  • Loading branch information
tejasbubane committed Apr 29, 2020
1 parent b5c18e1 commit 26d92ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Add new `Capybara/VisibilityMatcher` cop. ([@aried3r][])
* Ignore String constants by `RSpec/Describe`. ([@AlexWayfer][])
* Drop support for ruby 2.3. ([@bquorning][])
* Fix `RSpec/ScatteredLet` to detect `let` with proc argument. ([@tejasbubane][])

## 1.38.1 (2020-02-15)

Expand Down Expand Up @@ -497,3 +498,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@eitoball]: https://github.com/eitoball
[@aried3r]: https://github.com/aried3r
[@AlexWayfer]: https://github.com/AlexWayfer
[@tejasbubane]: https://github.com/tejasbubane
6 changes: 5 additions & 1 deletion lib/rubocop/rspec/language/node_pattern.rb
Expand Up @@ -17,7 +17,11 @@ module NodePattern

def_node_matcher :hook?, Hooks::ALL.block_pattern

def_node_matcher :let?, Helpers::ALL.block_pattern
def_node_matcher :let?, <<-PATTERN
{#{Helpers::ALL.block_pattern}
(send #{RSPEC} #{Helpers::ALL.node_pattern_union}
_ (block_pass ...))}
PATTERN

def_node_matcher :subject?, Subject::ALL.block_pattern
end
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/rspec/scattered_let_spec.rb
Expand Up @@ -25,4 +25,15 @@
end
RUBY
end

it 'flags `let` with proc argument' do
expect_offense(<<-RUBY)
RSpec.describe User do
let(:a) { a }
subject { User }
let(:user, &args[:build_user])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Group all let/let! blocks in the example group together.
end
RUBY
end
end

0 comments on commit 26d92ba

Please sign in to comment.