Sha256: 8967ffd6fce233b45e77ebd097e9daa42aaf0d38134da3c8d4fef37732b8e7e6

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::ConstantName do
  subject(:cop) { described_class.new }

  it 'registers an offense for camel case in const name' do
    inspect_source(cop,
                   'TopCase = 5')
    expect(cop.offenses.size).to eq(1)
  end

  it 'registers offenses for camel case in multiple const assignment' do
    inspect_source(cop,
                   'TopCase, Test2, TEST_3 = 5, 6, 7')
    expect(cop.offenses.size).to eq(2)
  end

  it 'registers an offense for snake case in const name' do
    inspect_source(cop,
                   'TOP_test = 5')
    expect(cop.offenses.size).to eq(1)
  end

  it 'allows screaming snake case in const name' do
    inspect_source(cop,
                   'TOP_TEST = 5')
    expect(cop.offenses).to be_empty
  end

  it 'allows screaming snake case in multiple const assignment' do
    inspect_source(cop,
                   'TOP_TEST, TEST_2 = 5, 6')
    expect(cop.offenses).to be_empty
  end

  it 'does not check names if rhs is a method call' do
    inspect_source(cop,
                   'AnythingGoes = test')
    expect(cop.offenses).to be_empty
  end

  it 'does not check names if rhs is a method call with block' do
    inspect_source(cop,
                   ['AnythingGoes = test do',
                    '  do_something',
                    'end'
                   ])
    expect(cop.offenses).to be_empty
  end

  it 'does not check if rhs is another constant' do
    inspect_source(cop,
                   'Parser::CurrentRuby = Parser::Ruby20')
    expect(cop.offenses).to be_empty
  end

  it 'checks qualified const names' do
    inspect_source(cop,
                   ['::AnythingGoes = 30',
                    'a::Bar_foo = 10'])
    expect(cop.offenses.size).to eq(2)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.29.1 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.29.0 spec/rubocop/cop/style/constant_name_spec.rb