Class: Gitlab::Styles::Rubocop::Cop::RSpec::EmptyLineAfterFinalLetItBe

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

Overview

Checks if there is an empty line after the last ‘let_it_be` block.

Examples:

# bad
let_it_be(:foo) { bar }
let_it_be(:something) { other }
it { does_something }

# good
let_it_be(:foo) { bar }
let_it_be(:something) { other }

it { does_something }

Constant Summary collapse

MSG =
'Add an empty line after the last `let_it_be`.'

Constants included from Rspec::Helpers

Rspec::Helpers::LET, Rspec::Helpers::LET_IT_BE_HELPERS

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_final_let_it_be.rb', line 37

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

  final_let_it_be = node.body.child_nodes.reverse.find { |child| let_it_be?(child) }

  return if final_let_it_be.nil?

  missing_separating_line_offense(final_let_it_be) { MSG }
end