Sha256: 9043b8048060894781c74b89313f9e315ab307478f1f42b423f0cb1728fdaec0

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offense for string concat at line end' do
    inspect_source(cop,
                   ['top = "test" +',
                    '"top"'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'registers an offense for dynamic string concat at line end' do
    inspect_source(cop,
                   ['top = "test#{x}" +',
                    '"top"'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts string concat on the same line' do
    inspect_source(cop,
                   ['top = "test" + "top"'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts string concat at line end when followed by comment' do
    inspect_source(cop,
                   ['top = "test" + # something',
                    '"top"'])
    expect(cop.offenses).to be_empty
  end

  it 'autocorrects by replacing + with \\' do
    corrected = autocorrect_source(cop,
                                   ['top = "test" +',
                                    '"top"'])
    expect(corrected).to eq ['top = "test" \\', '"top"'].join("\n")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.19.1 spec/rubocop/cop/style/line_end_concatenation_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/line_end_concatenation_spec.rb