Class: RuboCop::Cop::RSpec::PendingWithoutReason

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/pending_without_reason.rb

Overview

Checks for pending or skipped examples without reason.

Examples:

# bad
pending 'does something' do
end

# bad
it 'does something', :pending do
end

# bad
it 'does something' do
  pending
end

# bad
xdescribe 'something' do
end

# bad
skip 'does something' do
end

# bad
it 'does something', :skip do
end

# bad
it 'does something' do
  skip
end

# bad
it 'does something'

# good
it 'does something' do
  pending 'reason'
end

# good
it 'does something' do
  skip 'reason'
end

# good
it 'does something', pending: 'reason' do
end

# good
it 'does something', skip: 'reason' do
end

Constant Summary collapse

MSG =
'Give the reason for pending or skip.'

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

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_without_reason?(node) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 82

def_node_matcher :metadata_without_reason?, <<~PATTERN
  (send #rspec?
    {#ExampleGroups.all #Examples.all} ...
    {
      <(sym ${:pending :skip}) ...>
      (hash <(pair (sym ${:pending :skip}) true) ...>)
    }
  )
PATTERN

#on_send(node) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 102

def on_send(node)
  (node)
  return unless (parent = parent_node(node))

  if spec_group?(parent) || block_node_example_group?(node)
    on_skipped_by_example_method(node)
    on_skipped_by_example_group_method(node)
  elsif example?(parent)
    on_skipped_by_in_example_method(node)
  end
end

#pending_step_without_reason?(node) ⇒ Object



98
99
100
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 98

def_node_matcher :pending_step_without_reason?, <<~PATTERN
  (send nil? {:skip :pending})
PATTERN

#skipped_by_example_group_method?(node) ⇒ Object



93
94
95
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 93

def_node_matcher :skipped_by_example_group_method?, <<~PATTERN
  (send #rspec? ${#ExampleGroups.skipped} ...)
PATTERN

#skipped_by_example_method?(node) ⇒ Object



72
73
74
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 72

def_node_matcher :skipped_by_example_method?, <<~PATTERN
  (send nil? ${#Examples.skipped #Examples.pending})
PATTERN

#skipped_by_example_method_with_block?(node) ⇒ Object



77
78
79
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 77

def_node_matcher :skipped_by_example_method_with_block?, <<~PATTERN
  ({block numblock} (send nil? ${#Examples.skipped #Examples.pending} ...) ...)
PATTERN

#skipped_in_example?(node) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 63

def_node_matcher :skipped_in_example?, <<~PATTERN
  {
    (send nil? ${#Examples.skipped #Examples.pending})
    (block (send nil? ${#Examples.skipped}) ...)
    (numblock (send nil? ${#Examples.skipped}) ...)
  }
PATTERN