class RuboCop::Cop::RSpec::EmptyLineAfterExample
end
it { two }
it { one }
RSpec.describe Foo do
# bad
# AllowConsecutiveOneLiners: false
# RSpec/EmptyLineAfterExample:
# rubocop.yml
@example with AllowConsecutiveOneLiners configuration
end
it { two }
it { one }
RSpec.describe Foo do
# fair - it’s ok to have non-separated one-liners
end
end
it ‘does that’ do
end
it ‘does this’ do
RSpec.describe Foo do
# good
end
end
it ‘does that’ do
end
it ‘does this’ do
RSpec.describe Foo do
# bad
@example
Checks if there is an empty line after example blocks.
def allow_consecutive_one_liners?
def allow_consecutive_one_liners? cop_config['AllowConsecutiveOneLiners'] end
def allowed_one_liner?(node)
def allowed_one_liner?(node) consecutive_one_liner?(node) && allow_consecutive_one_liners? end
def consecutive_one_liner?(node)
def consecutive_one_liner?(node) node.line_count == 1 && next_one_line_example?(node) end
def next_one_line_example?(node)
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
def next_sibling(node)
def next_sibling(node) node.parent.children[node.sibling_index + 1] end
def on_block(node)
def on_block(node) return unless example?(node) return if last_child?(node) return if allowed_one_liner?(node) missing_separating_line(node) do |location| add_offense(node, location: location, message: format(MSG, example: node.method_name)) end end