Class: RuboCop::Cop::RSpec::Pending

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

Overview

Checks for any pending or skipped examples.

Examples:

# bad
describe MyClass do
  it "should be true"
end

describe MyClass do
  it "should be true", skip: true do
    expect(1).to eq(2)
  end
end

describe MyClass do
  it "should be true" do
    pending
  end
end

describe MyClass do
  xit "should be true" do
  end
end

# good
describe MyClass do
end

Constant Summary collapse

MSG =
'Pending spec found.'

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Methods included from RSpec::Language

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

Instance Method Details

#on_send(node) ⇒ Object


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

def on_send(node)
  return unless pending_block?(node) || skipped?(node)

  add_offense(node)
end

#pending_block?(node) ⇒ Object


55
56
57
58
59
60
61
62
# File 'lib/rubocop/cop/rspec/pending.rb', line 55

def_node_matcher :pending_block?,
send_pattern(<<~PATTERN)
  {
    #ExampleGroups.skipped
    #Examples.skipped
    #Examples.pending
  }
PATTERN

#skip_or_pending?(node) ⇒ Object


52
# File 'lib/rubocop/cop/rspec/pending.rb', line 52

def_node_matcher :skip_or_pending?, '{(sym :skip) (sym :pending)}'

#skippable?(node) ⇒ Object


38
39
40
41
# File 'lib/rubocop/cop/rspec/pending.rb', line 38

def_node_matcher :skippable?,
send_pattern(<<~PATTERN)
  {#ExampleGroups.regular #Examples.regular}
PATTERN

#skipped_in_metadata?(node) ⇒ Object


44
45
46
47
48
49
# File 'lib/rubocop/cop/rspec/pending.rb', line 44

def_node_matcher :skipped_in_metadata?, <<-PATTERN
  {
    (send _ _ <#skip_or_pending? ...>)
    (send _ _ ... (hash <(pair #skip_or_pending? { true str }) ...>))
  }
PATTERN