Sha256: 8a3736cc80089a362b44a113d09021a6dd487a43324e5e50dd685b0ef4b7e67b

Contents?: true

Size: 1.77 KB

Versions: 11

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

11 entries across 11 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/constant_name_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.28.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.27.1 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.27.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.26.1 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.26.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.25.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.24.1 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.24.0 spec/rubocop/cop/style/constant_name_spec.rb
rubocop-0.23.0 spec/rubocop/cop/style/constant_name_spec.rb