Module: RuboCop::RSpec::Language

Extended by:
NodePattern::Macros, NodePattern
Included in:
Cop::RSpec::Base, Cop::RSpec::ExplicitHelper, Cop::RSpec::InflectedHelper, Cop::RSpec::Metadata, Cop::RSpec::RemoveConst, AlignLetBrace, Concept
Defined in:
lib/rubocop/rspec/language.rb,
lib/rubocop/rspec/language/node_pattern.rb

Overview

Contains node matchers for common RSpec DSL.

RSpec allows for configuring aliases for commonly used DSL elements, e.g. example groups and hooks. It is possible to configure RuboCop RSpec to be able to properly detect these elements in the ‘RSpec/Language` section of the RuboCop YAML configuration file.

In addition to providing useful matchers, this class is responsible for using the configured aliases.

Defined Under Namespace

Modules: Helpers, HookScopes, NodePattern, Subjects

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from NodePattern

block_or_numblock_pattern, block_pattern, numblock_pattern, send_pattern

Class Attribute Details

.configObject

Returns the value of attribute config.



19
20
21
# File 'lib/rubocop/rspec/language.rb', line 19

def config
  @config
end

Instance Method Details

#example?(node) ⇒ Object



50
# File 'lib/rubocop/rspec/language.rb', line 50

def_node_matcher :example?, '(block (send nil? #Examples.all ...) ...)'

#example_group?(node) ⇒ Object



29
30
31
# File 'lib/rubocop/rspec/language.rb', line 29

def_node_matcher :example_group?, <<~PATTERN
  ({block numblock} (send #rspec? #ExampleGroups.all ...) ...)
PATTERN

#example_group_with_body?(node) ⇒ Object



45
46
47
# File 'lib/rubocop/rspec/language.rb', line 45

def_node_matcher :example_group_with_body?, <<~PATTERN
  (block (send #rspec? #ExampleGroups.all ...) args !nil?)
PATTERN

#explicit_rspec?(node) ⇒ Object



26
# File 'lib/rubocop/rspec/language.rb', line 26

def_node_matcher :explicit_rspec?, '(const {nil? cbase} :RSpec)'

#hook?(node) ⇒ Object



53
54
55
56
57
58
# File 'lib/rubocop/rspec/language.rb', line 53

def_node_matcher :hook?, <<~PATTERN
  {
    (numblock (send nil? #Hooks.all ...) ...)
    (block (send nil? #Hooks.all ...) ...)
  }
PATTERN

#include?(node) ⇒ Object



69
70
71
72
73
74
# File 'lib/rubocop/rspec/language.rb', line 69

def_node_matcher :include?, <<~PATTERN
  {
    (block (send nil? #Includes.all ...) ...)
    (send nil? #Includes.all ...)
  }
PATTERN

#let?(node) ⇒ Object



61
62
63
64
65
66
# File 'lib/rubocop/rspec/language.rb', line 61

def_node_matcher :let?, <<~PATTERN
  {
    (block (send nil? #Helpers.all ...) ...)
    (send nil? #Helpers.all _ block_pass)
  }
PATTERN

#rspec?(node) ⇒ Object



23
# File 'lib/rubocop/rspec/language.rb', line 23

def_node_matcher :rspec?, '{#explicit_rspec? nil?}'

#shared_group?(node) ⇒ Object



34
35
# File 'lib/rubocop/rspec/language.rb', line 34

def_node_matcher :shared_group?,
'(block (send #rspec? #SharedGroups.all ...) ...)'

#spec_group?(node) ⇒ Object



38
39
40
41
42
# File 'lib/rubocop/rspec/language.rb', line 38

def_node_matcher :spec_group?, <<~PATTERN
  ({block numblock} (send #rspec?
       {#SharedGroups.all #ExampleGroups.all}
    ...) ...)
PATTERN

#subject?(node) ⇒ Object



77
# File 'lib/rubocop/rspec/language.rb', line 77

def_node_matcher :subject?, '(block (send nil? #Subjects.all ...) ...)'