debian-mirror-gitlab/spec/rubocop/cop/gitlab/namespaced_class_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.7 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/gitlab/namespaced_class'
RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do
subject(:cop) { described_class.new }
it 'flags a class definition without namespace' do
expect_offense(<<~SOURCE)
class MyClass
^^^^^^^^^^^^^ #{described_class::MSG}
end
SOURCE
end
it 'flags a class definition with inheritance without namespace' do
expect_offense(<<~SOURCE)
class MyClass < ApplicationRecord
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
def some_method
true
end
end
SOURCE
end
it 'does not flag the class definition with namespace in separate lines' do
expect_no_offenses(<<~SOURCE)
module MyModule
class MyClass < ApplicationRecord
end
class MyOtherClass
def other_method
1 + 1
end
end
end
SOURCE
end
it 'does not flag the class definition with nested namespace in separate lines' do
expect_no_offenses(<<~SOURCE)
module TopLevelModule
module NestedModule
class MyClass
end
end
end
SOURCE
end
it 'does not flag the class definition nested inside namespaced class' do
expect_no_offenses(<<~SOURCE)
module TopLevelModule
class TopLevelClass
class MyClass
end
end
end
SOURCE
end
it 'does not flag a compact namespaced class definition' do
expect_no_offenses(<<~SOURCE)
class MyModule::MyClass < ApplicationRecord
end
SOURCE
end
end