Module: RuboCop::Cop::RSpec::Metadata

Extended by:
NodePattern::Macros
Includes:
RSpec::Language
Included in:
DuplicatedMetadata, EmptyMetadata, MetadataStyle, SortMetadata
Defined in:
lib/rubocop/cop/rspec/mixin/metadata.rb

Overview

Helper methods to find RSpec metadata.

Instance Method Summary collapse

Methods included from RSpec::Language

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

Instance Method Details

#metadata_in_block(node) ⇒ Object



26
27
28
# File 'lib/rubocop/cop/rspec/mixin/metadata.rb', line 26

def_node_search :metadata_in_block, <<~PATTERN
  (send (lvar %) #Hooks.all _ $...)
PATTERN

#on_block(node) ⇒ Object Also known as: on_numblock



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/cop/rspec/mixin/metadata.rb', line 30

def on_block(node)
  rspec_configure(node) do |block_var|
    (node, block_var) do ||
      ()
    end
  end

  (node) do ||
    ()
  end
end

#on_metadata(_symbols, _hash) ⇒ Object

Raises:

  • (::NotImplementedError)


43
44
45
# File 'lib/rubocop/cop/rspec/mixin/metadata.rb', line 43

def (_symbols, _hash)
  raise ::NotImplementedError
end

#rspec_configure(node) ⇒ Object



21
22
23
# File 'lib/rubocop/cop/rspec/mixin/metadata.rb', line 21

def_node_matcher :rspec_configure, <<~PATTERN
  (block (send #rspec? :configure) (args (arg $_)) ...)
PATTERN

#rspec_metadata(node) ⇒ Object



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

def_node_matcher :rspec_metadata, <<~PATTERN
  (block
    (send
      #rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all} _ $...)
    ...)
PATTERN