Sha256: e4cdd2ddba5ace46f31164b8a1be044e4507d8db7ad3df7de033291496efe7c4

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::EmptyLines do
  subject(:cop) { described_class.new }

  it 'registers an offense for consecutive empty lines' do
    inspect_source(cop,
                   ['test = 5', '', '', '', 'top'])
    expect(cop.offenses.size).to eq(2)
  end

  it 'auto-corrects consecutive empty lines' do
    corrected = autocorrect_source(cop,
                                   ['test = 5', '', '', '', 'top'])
    expect(corrected).to eq ['test = 5', '', 'top'].join("\n")
  end

  it 'works when there are no tokens' do
    inspect_source(cop,
                   ['#comment'])
    expect(cop.offenses).to be_empty
  end

  it 'handles comments' do
    inspect_source(cop,
                   ['test', '', '#comment', 'top'])
    expect(cop.offenses).to be_empty
  end

  it 'does not register an offense for empty lines in a string' do
    inspect_source(cop, ['result = "test



                                  string"'])
    expect(cop.offenses).to be_empty
  end

  it 'does not register an offense for heredocs with empty lines inside' do
    inspect_source(cop, ['str = <<-TEXT',
                         'line 1',
                         '',
                         '',
                         'line 2',
                         'TEXT',
                         'puts str'])
    expect(cop.offenses).to be_empty
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/empty_lines_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/empty_lines_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/empty_lines_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/empty_lines_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/empty_lines_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/empty_lines_spec.rb