Class: Rubocop::Cop::RSpec::EmptyLineAfterLetBlock

Inherits:
Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
RuboCop::Cop::RSpec::EmptyLineSeparation
Defined in:
lib/rubocop/cop/rspec/empty_line_after_let_block.rb

Overview

Checks if there is an empty line after let blocks.

Examples:

# bad
RSpec.describe Foo do
  let(:something) { 'something' }
  let(:another_thing) do
  end
  let(:something_else) do
  end
  let(:last_thing) { 'last thing' }
end

# good
RSpec.describe Foo do
  let(:something) { 'something' }
  let(:another_thing) do
  end

  let(:something_else) do
  end

  let(:last_thing) { 'last thing' }
end

# good - it's ok to have non-separated without do/end blocks
RSpec.describe Foo do
  let(:something) { 'something' }
  let(:last_thing) { 'last thing' }
end

Constant Summary collapse

MSG =
'Add an empty line after `%<let>s` block.'

Instance Method Summary collapse

Instance Method Details

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rubocop/cop/rspec/empty_line_after_let_block.rb', line 46

def on_block(node)
  RuboCop::RSpec::ExampleGroup.new(node).lets.each do |let|
    break if last_child?(let)
    next if let.single_line?

    missing_separating_line_offense(let) do |method|
      format(MSG, let: method)
      format(MSG, let: method)
    end
  end
end