Sha256: 799bec5523ddcbf485da2a14b0907c9043dbc7c33e2ad5945c21e846009aeaa9

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

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

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-discourse-3.9.3 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
rubocop-discourse-3.9.2 spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb