Sha256: 56d7724ca993091c721b64a40f9827f32b75562e42b6a0d20014a857b2557bcb

Contents?: true

Size: 1.43 KB

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.2.0 spec/rubocop/cops/hash_syntax_spec.rb