Class: RuboCop::Cop::RSpec::ImplicitSubject

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
ConfigurableEnforcedStyle
Defined in:
lib/rubocop/cop/rspec/implicit_subject.rb

Overview

Checks for usage of implicit subject (`is_expected` / `should`).

This cop can be configured using the `EnforcedStyle` option

Examples:

`EnforcedStyle: single_line_only`

# bad
it do
  is_expected.to be_truthy
end

# good
it { is_expected.to be_truthy }
it do
  expect(subject).to be_truthy
end

`EnforcedStyle: disallow`

# bad
it { is_expected.to be_truthy }

# good
it { expect(subject).to be_truthy }

Constant Summary collapse

MSG =
"Don't use implicit subject."

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_send(node) ⇒ Object


39
40
41
42
43
44
45
46
# File 'lib/rubocop/cop/rspec/implicit_subject.rb', line 39

def on_send(node)
  return unless implicit_subject?(node)
  return if valid_usage?(node)

  add_offense(node) do |corrector|
    autocorrect(corrector, node)
  end
end