class RuboCop::RSpec::ExampleGroup

Wrapper for RSpec example groups

Public Instance Methods

examples() click to toggle source
# File lib/rubocop/rspec/example_group.rb, line 28
def examples
  find_all_in_scope(node, :example?).map do |node|
    Example.new(node)
  end
end
hooks() click to toggle source
# File lib/rubocop/rspec/example_group.rb, line 34
def hooks
  find_all_in_scope(node, :hook?).map do |node|
    Hook.new(node)
  end
end
lets() click to toggle source
# File lib/rubocop/rspec/example_group.rb, line 20
def lets
  find_all_in_scope(node, :let?)
end
subjects() click to toggle source
# File lib/rubocop/rspec/example_group.rb, line 24
def subjects
  find_all_in_scope(node, :subject?)
end

Private Instance Methods

find_all(node, predicate) click to toggle source
# File lib/rubocop/rspec/example_group.rb, line 56
def find_all(node, predicate)
  if public_send(predicate, node)
    [node]
  elsif scope_change?(node) || example?(node)
    []
  else
    find_all_in_scope(node, predicate)
  end
end
find_all_in_scope(node, predicate) click to toggle source

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

# File lib/rubocop/rspec/example_group.rb, line 50
def find_all_in_scope(node, predicate)
  node.each_child_node.flat_map do |child|
    find_all(child, predicate)
  end
end