Sha256: 6f069c4fe04df98b4fdc96669da15a6df25c4fa154eff134d2044814d66b22ae

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

      it 'registers an offence for hash rocket syntax when new is possible' do
        inspect_source(hash_syntax, '', ['x = { :a => 0 }'])
        hash_syntax.offences.map(&:message).should ==
          ['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 }'])
        hash_syntax.offences.map(&:message).should ==
          ['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)'])
        hash_syntax.offences.map(&:message).should ==
          ['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 }'])
        hash_syntax.offences.map(&:message).should == []
      end

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.3.2 spec/rubocop/cops/hash_syntax_spec.rb
rubocop-0.3.1 spec/rubocop/cops/hash_syntax_spec.rb
rubocop-0.3.0 spec/rubocop/cops/hash_syntax_spec.rb
rubocop-0.2.1 spec/rubocop/cops/hash_syntax_spec.rb