diff --git a/lib/rubocop/cop/rspec/describe_class.rb b/lib/rubocop/cop/rspec/describe_class.rb index 059689830..6bdf4ffb9 100644 --- a/lib/rubocop/cop/rspec/describe_class.rb +++ b/lib/rubocop/cop/rspec/describe_class.rb @@ -51,8 +51,6 @@ class DescribeClass < Cop ) PATTERN - def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern - def on_top_level_describe(node, (described_value, _)) return if shared_group?(root_node) return if valid_describe?(node) diff --git a/lib/rubocop/cop/rspec/instance_variable.rb b/lib/rubocop/cop/rspec/instance_variable.rb index 3dfec9859..9ff31abd0 100644 --- a/lib/rubocop/cop/rspec/instance_variable.rb +++ b/lib/rubocop/cop/rspec/instance_variable.rb @@ -50,10 +50,6 @@ class InstanceVariable < Cop MSG = 'Avoid instance variables – use let, ' \ 'a method call, or a local variable (if possible).' - EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL - - def_node_matcher :spec_group?, EXAMPLE_GROUP_METHODS.block_pattern - def_node_matcher :dynamic_class?, <<-PATTERN (block (send (const nil? :Class) :new ...) ...) PATTERN diff --git a/lib/rubocop/cop/rspec/leaky_constant_declaration.rb b/lib/rubocop/cop/rspec/leaky_constant_declaration.rb index 155aef735..6431eefbe 100644 --- a/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +++ b/lib/rubocop/cop/rspec/leaky_constant_declaration.rb @@ -119,11 +119,8 @@ def on_module(node) private def inside_describe_block?(node) - node.each_ancestor(:block).any?(&method(:in_example_or_shared_group?)) + node.each_ancestor(:block).any?(&method(:spec_group?)) end - - def_node_matcher :in_example_or_shared_group?, - (ExampleGroups::ALL + SharedGroups::ALL).block_pattern end end end diff --git a/lib/rubocop/rspec/language/node_pattern.rb b/lib/rubocop/rspec/language/node_pattern.rb index 665b7ad70..de4c1da27 100644 --- a/lib/rubocop/rspec/language/node_pattern.rb +++ b/lib/rubocop/rspec/language/node_pattern.rb @@ -8,6 +8,10 @@ module NodePattern extend RuboCop::NodePattern::Macros def_node_matcher :example_group?, ExampleGroups::ALL.block_pattern + def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern + + spec_groups = ExampleGroups::ALL + SharedGroups::ALL + def_node_matcher :spec_group?, spec_groups.block_pattern def_node_matcher :example_group_with_body?, <<-PATTERN (block #{ExampleGroups::ALL.send_pattern} args [!nil?])