Class: Gitlab::Styles::Rubocop::Cop::RSpec::EmptyLineAfterSharedExample

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_shared_example.rb

Overview

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

Examples:

# bad
RSpec.describe Foo do
  it_behaves_like 'do this first'
  it_behaves_like 'does this' do
  end
  it_behaves_like 'does that' do
  end
  it_behaves_like 'do some more'
end

# good
RSpec.describe Foo do
  it_behaves_like 'do this first'
  it_behaves_like 'does this' do
  end

  it_behaves_like 'does that' do
  end

  it_behaves_like 'do some more'
end

# fair - it's ok to have non-separated without blocks
RSpec.describe Foo do
  it_behaves_like 'do this first'
  it_behaves_like 'does this'
end

Constant Summary collapse

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

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



51
52
53
54
55
56
57
58
59
# File 'lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb', line 51

def on_block(node)
  shared_examples(node) do
    break if last_child?(node)

    missing_separating_line_offense(node) do |method|
      format(MSG, example: method)
    end
  end
end