Class: RuboCop::Cop::RSpec::EmptyLineAfterExampleGroup

Inherits:
Cop
  • Object
show all
Includes:
RSpec::BlankLineSeparation
Defined in:
lib/rubocop/cop/rspec/empty_line_after_example_group.rb

Overview

Checks if there is an empty line after example group blocks.

Examples:

# bad
RSpec.describe Foo do
  describe '#bar' do
  end
  describe '#baz' do
  end
end

# good
RSpec.describe Foo do
  describe '#bar' do
  end

  describe '#baz' do
  end
end

Constant Summary collapse

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

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE

Constants included from RSpec::Language

RSpec::Language::ALL, RSpec::Language::RSPEC

Instance Method Summary collapse

Methods included from RSpec::BlankLineSeparation

#autocorrect, #last_child?, #missing_separating_line, #offending_loc

Methods included from RSpec::FinalEndLocation

#final_end_location

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#on_block(node) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubocop/cop/rspec/empty_line_after_example_group.rb', line 31

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

  missing_separating_line(node) do |location|
    add_offense(
      node,
      location: location,
      message: format(MSG, example_group: node.method_name)
    )
  end
end