Skip to content

Commit 172dfe8

Browse files
authored
Merge pull request #934 from mockdeep/rf-shared_groups
Pull example group node matchers up
2 parents 7e2d6dc + b327884 commit 172dfe8

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

lib/rubocop/cop/rspec/describe_class.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class DescribeClass < Cop
5151
)
5252
PATTERN
5353

54-
def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern
55-
5654
def on_top_level_describe(node, (described_value, _))
5755
return if shared_group?(root_node)
5856
return if valid_describe?(node)

lib/rubocop/cop/rspec/leaky_constant_declaration.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,8 @@ def on_module(node)
119119
private
120120

121121
def inside_describe_block?(node)
122-
node.each_ancestor(:block).any?(&method(:in_example_or_shared_group?))
122+
node.each_ancestor(:block).any?(&method(:spec_group?))
123123
end
124-
125-
def_node_matcher :in_example_or_shared_group?,
126-
(ExampleGroups::ALL + SharedGroups::ALL).block_pattern
127124
end
128125
end
129126
end

lib/rubocop/rspec/language/node_pattern.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module NodePattern
88
extend RuboCop::NodePattern::Macros
99

1010
def_node_matcher :example_group?, ExampleGroups::ALL.block_pattern
11+
def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern
12+
13+
spec_groups = ExampleGroups::ALL + SharedGroups::ALL
14+
def_node_matcher :spec_group?, spec_groups.block_pattern
1115

1216
def_node_matcher :example_group_with_body?, <<-PATTERN
1317
(block #{ExampleGroups::ALL.send_pattern} args [!nil?])

0 commit comments

Comments
 (0)