Module: RuboCop::RSpec::Language

Extended by:
NodePattern::Macros
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

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, Subjects

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#example?(node) ⇒ Object



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

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

#example_group?(node) ⇒ Object



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

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

#example_group_with_body?(node) ⇒ Object



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

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

#explicit_rspec?(node) ⇒ Object



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

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

#hook?(node) ⇒ Object



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

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

#include?(node) ⇒ Object



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

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

#let?(node) ⇒ Object



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

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

#rspec?(node) ⇒ Object



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

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

#shared_group?(node) ⇒ Object



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

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

#spec_group?(node) ⇒ Object



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

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

#subject?(node) ⇒ Object



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

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