lib/rubocop/rspec/example_group.rb in rubocop-rspec-2.0.0.pre vs lib/rubocop/rspec/example_group.rb in rubocop-rspec-2.0.0

- old
+ new

@@ -8,36 +8,46 @@ # # 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 + Includes::ALL - ).block_pattern + def_node_matcher :scope_change?, + block_pattern(<<~PATTERN) + { + #SharedGroups.all + #ExampleGroups.all + #Includes.all + } + PATTERN def lets find_all_in_scope(node, :let?) end def subjects find_all_in_scope(node, :subject?) end def examples - find_all_in_scope(node, :example?).map(&Example.public_method(:new)) + find_all_in_scope(node, :example?).map do |node| + Example.new(node) + end end def hooks - find_all_in_scope(node, :hook?).map(&Hook.public_method(:new)) + find_all_in_scope(node, :hook?).map do |node| + Hook.new(node) + end end private # Recursively search for predicate within the current scope # # Searches node and halts when a scope change is detected # # @param node [RuboCop::AST::Node] node to recursively search + # @param predicate [Symbol] method to call with node as argument # # @return [Array<RuboCop::AST::Node>] discovered nodes def find_all_in_scope(node, predicate) node.each_child_node.flat_map do |child| find_all(child, predicate)