Sha256: 8c81b09178939e81c29fd35e97534ed1c1257f96e4cb860ba92b45a5662bcdad

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offense for colon without space after it' do
    # TODO: There is double reporting of the last colon (also from
    # SpaceAroundOperators).
    inspect_source(cop, ['x = w ? {a:3}:4'])
    expect(cop.messages).to eq(['Space missing after colon.'] * 2)
    expect(cop.highlights).to eq([':'] * 2)
  end

  it 'accepts colons in symbols' do
    inspect_source(cop, ['x = :a'])
    expect(cop.messages).to be_empty
  end

  if RUBY_VERSION >= '2.1'
    it 'accepts colons denoting required keyword argument' do
      inspect_source(cop, ['def initialize(table:, nodes:)',
                           'end'])
      expect(cop.messages).to be_empty
    end
  end

  it 'accepts colons in strings' do
    inspect_source(cop, ["str << ':'"])
    expect(cop.messages).to be_empty
  end

  it 'auto-corrects missing space' do
    new_source = autocorrect_source(cop, 'x = w ? {a:3}:4')
    expect(new_source).to eq('x = w ? {a: 3}: 4')
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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