Sha256: db4507e61f30dd7f27484f90e9f60651bf8d9f104d75278ab69d514a9a45a167

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe HashSyntax do
        let(:hash_syntax) { HashSyntax.new }

        it 'registers offence for hash rocket syntax when new is possible' do
          inspect_source(hash_syntax, ['x = { :a => 0 }'])
          expect(hash_syntax.offences.map(&:message)).to eq(
            ['Ruby 1.8 hash syntax detected'])
        end

        it 'registers an offence for mixed syntax when new is possible' do
          inspect_source(hash_syntax, ['x = { :a => 0, b: 1 }'])
          expect(hash_syntax.offences.map(&:message)).to eq(
            ['Ruby 1.8 hash syntax detected'])
        end

        it 'registers an offence for hash rockets in method calls' do
          inspect_source(hash_syntax, ['func(3, :a => 0)'])
          expect(hash_syntax.offences.map(&:message)).to eq(
            ['Ruby 1.8 hash syntax detected'])
        end

        it 'accepts hash rockets when keys have different types' do
          inspect_source(hash_syntax, ['x = { :a => 0, "b" => 1 }'])
          expect(hash_syntax.offences.map(&:message)).to be_empty
        end

        it 'accepts hash rockets when keys have whitespaces in them' do
          inspect_source(hash_syntax, ['x = { :"t o" => 0 }'])
          expect(hash_syntax.offences.map(&:message)).to be_empty
        end

        it 'accepts hash rockets when keys have special symbols in them' do
          inspect_source(hash_syntax, ['x = { :"\tab" => 1 }'])
          expect(hash_syntax.offences.map(&:message)).to be_empty
        end

        it 'accepts new syntax in a hash literal' do
          inspect_source(hash_syntax, ['x = { a: 0, b: 1 }'])
          expect(hash_syntax.offences.map(&:message)).to be_empty
        end

        it 'accepts new syntax in method calls' do
          inspect_source(hash_syntax, ['func(3, a: 0)'])
          expect(hash_syntax.offences.map(&:message)).to be_empty
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.12.0 spec/rubocop/cop/style/hash_syntax_spec.rb
rubocop-0.11.1 spec/rubocop/cop/style/hash_syntax_spec.rb
rubocop-0.11.0 spec/rubocop/cops/style/hash_syntax_spec.rb