diff --git a/lib/rubocop/cop/rspec/describe_class.rb b/lib/rubocop/cop/rspec/describe_class.rb index 2eb08b0d2..cfe63506f 100644 --- a/lib/rubocop/cop/rspec/describe_class.rb +++ b/lib/rubocop/cop/rspec/describe_class.rb @@ -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