diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/rubocop/cop/gitlab/namespaced_class_spec.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/rubocop/cop/gitlab/namespaced_class_spec.rb')
-rw-r--r-- | spec/rubocop/cop/gitlab/namespaced_class_spec.rb | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb new file mode 100644 index 00000000000..d1f61aa5afb --- /dev/null +++ b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rubocop' +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 |