lib/rubocop/rspec/example_group.rb in rubocop-rspec-1.15.1 vs lib/rubocop/rspec/example_group.rb in rubocop-rspec-1.16.0
- old
+ new
@@ -8,28 +8,51 @@
#
# Detect if the node is an example group or shared example
#
# Selectors which indicate that we should stop searching
#
- def_node_matcher :scope_change?,
- (ExampleGroups::ALL + SharedGroups::ALL).block_pattern
+ def_node_matcher :scope_change?, (
+ ExampleGroups::ALL + SharedGroups::ALL + Includes::ALL
+ ).block_pattern
# @!method hook(node)
#
# Detect if node is `before`, `after`, `around`
def_node_matcher :hook, <<-PATTERN
(block {$(send nil #{Hooks::ALL.node_pattern_union} ...)} ...)
PATTERN
+ def_node_matcher :subject, Subject::ALL.block_pattern
+
+ def subjects
+ subjects_in_scope(node)
+ end
+
def examples
examples_in_scope(node).map(&Example.public_method(:new))
end
def hooks
hooks_in_scope(node).map(&Hook.public_method(:new))
end
private
+
+ def subjects_in_scope(node)
+ node.each_child_node.flat_map do |child|
+ find_subjects(child)
+ end
+ end
+
+ def find_subjects(node)
+ return [] if scope_change?(node)
+
+ if subject(node)
+ [node]
+ else
+ subjects_in_scope(node)
+ end
+ end
def hooks_in_scope(node)
node.each_child_node.flat_map do |child|
find_hooks(child)
end