class RuboCop::Cop::RSpec::EmptyLineAfterExample

Checks if there is an empty line after example blocks.

@example

# bad
RSpec.describe Foo do
  it 'does this' do
  end
  it 'does that' do
  end
end

# good
RSpec.describe Foo do
  it 'does this' do
  end

  it 'does that' do
  end
end

# fair - it's ok to have non-separated one-liners
RSpec.describe Foo do
  it { one }
  it { two }
end

@example with AllowConsecutiveOneLiners configuration

# rubocop.yml
# RSpec/EmptyLineAfterExample:
#   AllowConsecutiveOneLiners: false

# bad
RSpec.describe Foo do
  it { one }
  it { two }
end

Constants

MSG

Public Instance Methods

allow_consecutive_one_liners?() click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_example.rb, line 63
def allow_consecutive_one_liners?
  cop_config['AllowConsecutiveOneLiners']
end
allowed_one_liner?(node) click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_example.rb, line 59
def allowed_one_liner?(node)
  consecutive_one_liner?(node) && allow_consecutive_one_liners?
end
consecutive_one_liner?(node) click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_example.rb, line 67
def consecutive_one_liner?(node)
  node.line_count == 1 && next_one_line_example?(node)
end
next_one_line_example?(node) click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_example.rb, line 71
def next_one_line_example?(node)
  next_sibling = next_sibling(node)
  return unless next_sibling
  return unless example?(next_sibling)

  next_sibling.line_count == 1
end
next_sibling(node) click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_example.rb, line 79
def next_sibling(node)
  node.parent.children[node.sibling_index + 1]
end
on_block(node) click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_example.rb, line 50
def on_block(node)
  return unless example?(node)
  return if allowed_one_liner?(node)

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