Sha256: e249e86486b1f1adf9ff63820e96efeae0140e56f735a9c2e1b795a2fff5b1bd

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::BlockEndNewline do
  subject(:cop) { described_class.new }

  it 'does not register an offense for a one-liner' do
    inspect_source(cop, 'test do foo end')
    expect(cop.messages).to be_empty
  end

  it 'does not register an offense for multiline blocks with newlines before '\
     'the end' do
    inspect_source(cop,
                   ['test do',
                    '  foo',
                    'end'])
    expect(cop.messages).to be_empty
  end

  it 'registers an offense when multiline block end is not on its own line' do
    inspect_source(cop,
                   ['test do',
                    '  foo end'
                   ])
    expect(cop.messages)
      .to eq(['Expression at 2, 7 should be on its own line.'])
  end

  it 'registers an offense when multiline block } is not on its own line' do
    inspect_source(cop,
                   ['test {',
                    '  foo }'
                   ])
    expect(cop.messages)
      .to eq(['Expression at 2, 7 should be on its own line.'])
  end

  it 'autocorrects a do/end block where the end is not on its own line' do
    src =  ['test do',
            '  foo end']

    new_source = autocorrect_source(cop, src)

    expect(new_source).to eq(['test do',
                              '  foo ',
                              'end'].join("\n"))
  end

  it 'autocorrects a {} block where the } is not on its own line' do
    src =  ['test {',
            '  foo }']

    new_source = autocorrect_source(cop, src)

    expect(new_source).to eq(['test {',
                              '  foo ',
                              '}'].join("\n"))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.29.1 spec/rubocop/cop/style/block_end_newline_spec.rb
rubocop-0.29.0 spec/rubocop/cop/style/block_end_newline_spec.rb