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 deec968
Show file tree
Hide file tree
Showing 4 changed files with 22 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
8 changes: 8 additions & 0 deletions lib/rubocop/rspec/language.rb
Expand Up @@ -28,6 +28,14 @@ def block_pattern
"(block #{send_pattern} ...)"
end

def block_pass_pattern
"(send #{RSPEC} #{node_pattern_union} _ block_pass)"
end

def block_or_block_pass_pattern
"{#{block_pattern} #{block_pass_pattern}}"
end

def send_pattern
"(send #{RSPEC} #{node_pattern_union} ...)"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/rspec/language/node_pattern.rb
Expand Up @@ -17,7 +17,7 @@ module NodePattern

def_node_matcher :hook?, Hooks::ALL.block_pattern

def_node_matcher :let?, Helpers::ALL.block_pattern
def_node_matcher :let?, Helpers::ALL.block_or_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 deec968

Please sign in to comment.