Sha256: bb924e5ffe03a139dfde639cbd6de041d78424afe1e30eace2929cb84db3d3cb

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::TrailingBlankLines do
  subject(:cop) { described_class.new(config) }
  let(:config) do
    Rubocop::Config.new('TrailingWhitespace' => { 'Enabled' => true })
  end

  it 'accepts final newline' do
    inspect_source(cop, ['x = 0', ''])
    expect(cop.offenses).to be_empty
  end

  it 'registers an offense for multiple trailing blank lines' do
    inspect_source(cop, ['x = 0', '', '', '', ''])
    expect(cop.offenses.size).to eq(1)
    expect(cop.messages).to eq(['3 trailing blank lines detected.'])
  end

  it 'auto-corrects unwanted blank lines' do
    new_source = autocorrect_source(cop, ['x = 0', '', '', '', ''])
    expect(new_source).to eq(['x = 0', ''].join("\n"))
  end

  it 'does not auto-correct if it interferes with TrailingWhitespace' do
    original = ['x = 0', '', '  ', '', '']
    new_source = autocorrect_source(cop, original)
    expect(new_source).to eq(original.join("\n"))
  end

  context 'with TrailingWhitespace disabled' do
    let(:config) do
      Rubocop::Config.new('TrailingWhitespace' => { 'Enabled' => false })
    end

    it 'auto-corrects even if some lines have space' do
      new_source = autocorrect_source(cop, ['x = 0', '', '  ', '', ''])
      expect(new_source).to eq(['x = 0', ''].join("\n"))
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.20.1 spec/rubocop/cop/style/trailing_blank_lines_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/trailing_blank_lines_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/trailing_blank_lines_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/trailing_blank_lines_spec.rb