summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-23 15:09:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-23 15:09:36 +0000
commit074d013e1eb3f6e0c27f96a3be8b9361254c8a98 (patch)
treef185c474ddc8624a4793c84b0b1f4cc07349694b /spec/rubocop
parent8f9beefac3774b30e911fb00a68f4c7a5244cf27 (diff)
downloadgitlab-ce-074d013e1eb3f6e0c27f96a3be8b9361254c8a98.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb105
1 files changed, 105 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
new file mode 100644
index 00000000000..87dd2f14b31
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
@@ -0,0 +1,105 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../../rubocop/cop/gitlab/duplicate_spec_location'
+
+describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
+ include RuboCop::RSpec::ExpectOffense
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ let(:rails_root) { '../../../../' }
+
+ def full_path(path)
+ File.expand_path(File.join(rails_root, path), __dir__)
+ end
+
+ context 'Non-EE spec file' do
+ it 'registers no offenses' do
+ expect_no_offenses(<<~SOURCE.strip_indent, full_path('spec/foo_spec.rb'))
+ describe 'Foo' do
+ end
+ SOURCE
+ end
+ end
+
+ context 'Non-EE application file' do
+ it 'registers no offenses' do
+ expect_no_offenses(<<~SOURCE.strip_indent, full_path('app/models/blog_post.rb'))
+ class BlogPost
+ end
+ SOURCE
+ end
+ end
+
+ context 'EE application file' do
+ it 'registers no offenses' do
+ expect_no_offenses(<<~SOURCE.strip_indent, full_path('ee/app/models/blog_post.rb'))
+ class BlogPost
+ end
+ SOURCE
+ end
+ end
+
+ context 'EE spec file for EE only code' do
+ let(:spec_file_path) { full_path('ee/spec/controllers/foo_spec.rb') }
+
+ it 'registers no offenses' do
+ expect_no_offenses(<<~SOURCE.strip_indent, spec_file_path)
+ describe 'Foo' do
+ end
+ SOURCE
+ end
+
+ context 'there is a duplicate file' do
+ before do
+ allow(File).to receive(:exist?).and_call_original
+
+ allow(File).to receive(:exist?)
+ .with(full_path('ee/spec/controllers/ee/foo_spec.rb'))
+ .and_return(true)
+ end
+
+ it 'marks the describe as offending' do
+ expect_offense(<<~SOURCE.strip_indent, spec_file_path)
+ describe 'Foo' do
+ ^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/ee/foo_spec.rb`.
+ end
+ SOURCE
+ end
+ end
+ end
+
+ context 'EE spec file for EE extension' do
+ let(:spec_file_path) { full_path('ee/spec/controllers/ee/foo_spec.rb') }
+
+ it 'registers no offenses' do
+ expect_no_offenses(<<~SOURCE.strip_indent, spec_file_path)
+ describe 'Foo' do
+ end
+ SOURCE
+ end
+
+ context 'there is a duplicate file' do
+ before do
+ allow(File).to receive(:exist?).and_call_original
+
+ allow(File).to receive(:exist?)
+ .with(full_path('ee/spec/controllers/foo_spec.rb'))
+ .and_return(true)
+ end
+
+ it 'marks the describe as offending' do
+ expect_offense(<<~SOURCE.strip_indent, spec_file_path)
+ describe 'Foo' do
+ ^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/foo_spec.rb`.
+ end
+ SOURCE
+ end
+ end
+ end
+end