Class: RuboCop::RSpec::ExampleGroup

Inherits:
Concept
  • Object
show all
Defined in:
lib/rubocop/rspec/example_group.rb

Overview

Wrapper for RSpec example groups

Instance Method Summary collapse

Methods inherited from Concept

#eql?, #hash, #initialize, #to_node

Methods included from Language::NodePattern

#block_or_numblock_pattern, #block_pattern, #numblock_pattern, #send_pattern

Methods included from Language

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Constructor Details

This class inherits a constructor from RuboCop::RSpec::Concept

Instance Method Details

#examplesObject



28
29
30
31
32
# 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

#hooksObject



34
35
36
37
38
# 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

#letsObject



20
21
22
# File 'lib/rubocop/rspec/example_group.rb', line 20

def lets
  find_all_in_scope(node, :let?)
end

#scope_change?(node) ⇒ Object

Detect if the node is an example group or shared example

Selectors which indicate that we should stop searching



13
14
15
16
17
18
# File 'lib/rubocop/rspec/example_group.rb', line 13

def_node_matcher :scope_change?, <<~PATTERN
  (block {
    (send #rspec? {#SharedGroups.all #ExampleGroups.all} ...)
    (send nil? #Includes.all ...)
  } ...)
PATTERN

#subjectsObject



24
25
26
# File 'lib/rubocop/rspec/example_group.rb', line 24

def subjects
  find_all_in_scope(node, :subject?)
end