Sha256: 5df51adc9fa15071534a018a1d69fe9a126f38586e9629f28e576f651d84ace8

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 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 }'])
        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 special symbols in them' do
        inspect_source(hash_syntax, ['x = { :"t o" => 0, :"\xab" => 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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 spec/rubocop/cops/hash_syntax_spec.rb
rubocop-0.8.2 spec/rubocop/cops/hash_syntax_spec.rb
rubocop-0.8.1 spec/rubocop/cops/hash_syntax_spec.rb
rubocop-0.8.0 spec/rubocop/cops/hash_syntax_spec.rb