Class: RuboCop::Cop::RSpec::LetSetup

Inherits:
RuboCop::Cop show all
Includes:
RSpec::Language, RSpec::Language::NodePattern, RSpec::SpecOnly, RSpec::TopLevelDescribe
Defined in:
lib/rubocop/cop/rspec/let_setup.rb

Overview

Checks unreferenced ‘let!` calls being used for test setup.

Examples:

# Bad
let!(:my_widget) { create(:widget) }

it 'counts widgets' do
  expect(Widget.count).to eq(1)
end

# Good
it 'counts widgets' do
  create(:widget)
  expect(Widget.count).to eq(1)
end

# Good
before { create(:widget) }

it 'counts widgets' do
  expect(Widget.count).to eq(1)
end

Constant Summary collapse

MSG =
'Do not use `let!` for test setup.'.freeze

Constants included from RSpec::SpecOnly

RSpec::SpecOnly::DEFAULT_CONFIGURATION

Constants included from RSpec::Language

RSpec::Language::ALL

Instance Method Summary collapse

Methods included from RSpec::SpecOnly

#relevant_file?

Methods included from RSpec::TopLevelDescribe

#on_send

Instance Method Details

#on_block(node) ⇒ Object



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

def on_block(node)
  return unless example_group?(node)

  unused_let_bang(node) do |let|
    add_offense(let, :expression)
  end
end