Sha256: 7366e69bf692c816f87371ee88cf382b4ef0b0525ea8ee2393ce7129ebd22dfb

Contents?: true

Size: 1.77 KB

Versions: 6

Compression:

Stored size: 1.77 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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/constant_name_spec.rb