Sha256: d1415abc9c864e3e89eead4dcb828e27d07d52fe705bb003fdacabd5f1f8dfeb

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offence for an array literal with spaces inside' do
    inspect_source(cop, ['a = [1, 2 ]',
                         'b = [ 1, 2]'])
    expect(cop.messages).to eq(
      ['Space inside square brackets detected.',
       'Space inside square brackets detected.'])
  end

  it 'accepts space inside strings within square brackets' do
    inspect_source(cop, ["['Encoding:',",
                         " '  Enabled: false']"])
    expect(cop.messages).to be_empty
  end

  it 'accepts space inside square brackets if on its own row' do
    inspect_source(cop, ['a = [',
                         '     1, 2',
                         '    ]'])
    expect(cop.messages).to be_empty
  end

  it 'accepts square brackets as method name' do
    inspect_source(cop, ['def Vector.[](*array)',
                         'end'])
    expect(cop.messages).to be_empty
  end

  it 'accepts square brackets called with method call syntax' do
    inspect_source(cop, ['subject.[](0)'])
    expect(cop.messages).to be_empty
  end

  it 'only reports a single space once' do
    inspect_source(cop, ['[ ]'])
    expect(cop.messages).to eq(
      ['Space inside square brackets detected.'])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.14.1 spec/rubocop/cop/style/space_inside_brackets_spec.rb
rubocop-0.14.0 spec/rubocop/cop/style/space_inside_brackets_spec.rb