Skip to content

Commit f5dbe20

Browse files
dgollahonbquorning
authored andcommitted
Fix focus detection for mixed array/hash metadata
- Due to the order of how the patterns were defined, the hash capture took priority over the broader capture pattern. I've changed the matching logic to be directly represented by the any-order matcher patterns which also simplifies the code, if just slightly. - Closes #775
1 parent a913dfb commit f5dbe20

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/rubocop/cop/rspec/focus.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ class Focus < Cop
3232

3333
FOCUSABLE_SELECTORS = focusable.node_pattern_union
3434

35-
FOCUS_SYMBOL = s(:sym, :focus)
36-
FOCUS_TRUE = s(:pair, FOCUS_SYMBOL, s(:true))
37-
3835
def_node_matcher :metadata, <<-PATTERN
39-
{(send #{RSPEC} #{FOCUSABLE_SELECTORS} ... (hash $...))
40-
(send #{RSPEC} #{FOCUSABLE_SELECTORS} $...)}
36+
{(send #{RSPEC} #{FOCUSABLE_SELECTORS} <$(sym :focus) ...>)
37+
(send #{RSPEC} #{FOCUSABLE_SELECTORS} ... (hash <$(pair (sym :focus) true) ...>))}
4138
PATTERN
4239

4340
def_node_matcher :focused_block?, focused.send_pattern
@@ -53,10 +50,7 @@ def on_send(node)
5350
def focus_metadata(node, &block)
5451
yield(node) if focused_block?(node)
5552

56-
metadata(node) do |matches|
57-
matches.grep(FOCUS_SYMBOL, &block)
58-
matches.grep(FOCUS_TRUE, &block)
59-
end
53+
metadata(node, &block)
6054
end
6155
end
6256
end

spec/rubocop/cop/rspec/focus_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,11 @@
136136
^^^^^^^^^^^^ Focused spec found.
137137
RUBY
138138
end
139+
140+
it 'flags rspec example blocks that include `:focus` preceding a hash' do
141+
expect_offense(<<-RUBY)
142+
describe 'test', :focus, js: true do; end
143+
^^^^^^ Focused spec found.
144+
RUBY
145+
end
139146
end

0 commit comments

Comments
 (0)