Sha256: 97a4206eb9260d47a1018af40ea1146b52a7b1598da12a7a852d9314f2d5ea94

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require "spec_helper"

RSpec.describe RuboCop::Cop::Discourse::Plugins::NamespaceConstants, :config do
  subject(:cop) { described_class.new(config) }

  let(:config) { RuboCop::Config.new }

  context "when defining a constant outside any namespace" do
    it "registers an offense" do
      expect_offense(<<~RUBY)
        MY_CONSTANT = "my_value"
        ^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/NamespaceConstants: Don’t define constants outside a class or a module.

        class MyClass
          MY_CONSTANT = "my_value"
        end
      RUBY
    end
  end

  context "when defining a constant inside a class" do
    it "does not register an offense" do
      expect_no_offenses(<<~RUBY)
        class MyClass
          MY_CONSTANT = "my_value"
        end
      RUBY
    end
  end

  context "when defining a constant inside a module" do
    it "does not register an offense" do
      expect_no_offenses(<<~RUBY)
        module MyModule
          MY_CONSTANT = "my_value"
        end
      RUBY
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-discourse-3.9.1 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.9.0 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.8.6 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.8.5 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.8.4 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.8.3 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.8.2 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.8.1 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.7.1 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.7.0 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb