Skip to content

Commit aa1b63e

Browse files
committed
Make EmptyExampleGroup use dynamic hooks
1 parent 797f172 commit aa1b63e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/rubocop/cop/rspec/empty_example_group.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ class EmptyExampleGroup < Base
110110
# end
111111
#
112112
# @param node [RuboCop::AST::Node]
113+
# @param %1 [Proc] Function to match hooks
113114
# @return [Array<RuboCop::AST::Node>] matching nodes
114115
def_node_matcher :examples_inside_block?, <<~PATTERN
115-
(block !#{Hooks::ALL.send_pattern} _ #examples?)
116+
(block !#{SEND_PATTERN} _ #examples?(%1))
116117
PATTERN
117118

118119
# @!method examples_directly_or_in_block?(node)
@@ -124,11 +125,12 @@ class EmptyExampleGroup < Base
124125
# (1..5).each { |divisor| it { is_expected.to divide_by(divisor) } }
125126
#
126127
# @param node [RuboCop::AST::Node]
128+
# @param %1 [Proc] Function to match hooks
127129
# @return [Array<RuboCop::AST::Node>] matching nodes
128130
def_node_matcher :examples_directly_or_in_block?, <<~PATTERN
129131
{
130132
#example_or_group_or_include?
131-
#examples_inside_block?
133+
#examples_inside_block?(%1)
132134
}
133135
PATTERN
134136

@@ -143,17 +145,18 @@ class EmptyExampleGroup < Base
143145
# before { it { whatever here wont run anyway } }
144146
#
145147
# @param node [RuboCop::AST::Node]
148+
# @param %1 [Proc] Function to match hooks
146149
# @return [Array<RuboCop::AST::Node>] matching nodes
147150
def_node_matcher :examples?, <<~PATTERN
148151
{
149-
#examples_directly_or_in_block?
150-
(begin <#examples_directly_or_in_block? ...>)
152+
#examples_directly_or_in_block?(%1)
153+
(begin <#examples_directly_or_in_block?(%1) ...>)
151154
}
152155
PATTERN
153156

154157
def on_block(node)
155158
example_group_body(node) do |body|
156-
add_offense(node.send_node) unless examples?(body)
159+
add_offense(node.send_node) unless examples?(body, rspec_hooks)
157160
end
158161
end
159162

0 commit comments

Comments
 (0)