Sha256: 5b77061dfd0e91b747136aa30bcad4e7a7aec6e8790e716ade888ca1499fbba9

Contents?: true

Size: 1.66 KB

Versions: 8

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

8 entries across 8 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/block_end_newline_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/block_end_newline_spec.rb
rubocop-0.28.0 spec/rubocop/cop/style/block_end_newline_spec.rb
rubocop-0.27.1 spec/rubocop/cop/style/block_end_newline_spec.rb
rubocop-0.27.0 spec/rubocop/cop/style/block_end_newline_spec.rb
rubocop-0.26.1 spec/rubocop/cop/style/block_end_newline_spec.rb
rubocop-0.26.0 spec/rubocop/cop/style/block_end_newline_spec.rb
rubocop-0.25.0 spec/rubocop/cop/style/block_end_newline_spec.rb