Sha256: 6c539b9db7da28040d799820dbc3961d8a649ed601344778f9825595de436789
Contents?: true
Size: 1.94 KB
Versions: 10
Compression:
Stored size: 1.94 KB
Contents
# frozen_string_literal: true require "spec_helper" RSpec.describe RuboCop::Cop::Discourse::Plugins::NamespaceMethods, :config do subject(:cop) { described_class.new(config) } let(:config) { RuboCop::Config.new } context "when defining a method outside any namespace" do it "registers an offense" do expect_offense(<<~RUBY) def my_method ^^^^^^^^^^^^^ Discourse/Plugins/NamespaceMethods: Don’t define methods outside a class or a module. "my_value" end class MyClass def my_method "my_method" end end RUBY end end context "when defining a method inside a class" do context "when defining an instance method" do it "does not register an offense" do expect_no_offenses(<<~RUBY) class MyClass def my_method "my_value" end end RUBY end end context "when defining a class method" do it "does not register an offense" do expect_no_offenses(<<~RUBY) class MyClass class << self def my_method "my_value" end def another_method "plop" end end end RUBY end end end context "when defining a method inside a module" do context "when defining an instance method" do it "does not register an offense" do expect_no_offenses(<<~RUBY) module MyModule def my_method "my_value" end end RUBY end end context "when defining a class method" do it "does not register an offense" do expect_no_offenses(<<~RUBY) module MyModule class << self def my_method "my_value" end end end RUBY end end end end
Version data entries
10 entries across 10 versions & 1 rubygems