From 7bcab69acdcb8afd564b974999a2562a9b5689e5 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Mon, 3 Aug 2020 02:28:50 +0300 Subject: [PATCH] fixup! Simplify DescribeClass node pattern --- lib/rubocop/cop/rspec/describe_class.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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