Skip to content

Commit

Permalink
fixup! Simplify DescribeClass node pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Aug 2, 2020
1 parent 1a3e974 commit 7bcab69
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/rubocop/cop/rspec/describe_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ class DescribeClass < Base
)
PATTERN

def_node_matcher :send_node, '(block $send ...)'

def_node_matcher :example_group_with_rails_metadata?, <<~PATTERN
(send #rspec? :describe ... (hash <#rails_metadata? ...>))
PATTERN

def_node_matcher :not_a_const_described, <<~PATTERN
(block
[ (send #rspec? :describe $[!const !#string_constant?] ...)
!(send #rspec? :describe ... (hash <#rails_metadata? ...>)) ]
...
)
(send #rspec? :describe $[!const !#string_constant?] ...)
PATTERN

def on_top_level_group(top_level_node)
not_a_const_described(top_level_node) do |described|
return if example_group_with_rails_metadata?(top_level_node.send_node)

not_a_const_described(top_level_node.send_node) do |described|
add_offense(described)
end
end
Expand Down

0 comments on commit 7bcab69

Please sign in to comment.