2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'rubocop_spec_helper'
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
require_relative '../../../../rubocop/cop/rspec/duplicate_spec_location'
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
RSpec.describe RuboCop::Cop::RSpec::DuplicateSpecLocation do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:rails_root) { '../../../../' }
|
|
|
|
|
|
|
|
def full_path(path)
|
|
|
|
File.expand_path(File.join(rails_root, path), __dir__)
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'for a non-EE spec file' do
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'registers no offenses' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~SOURCE, full_path('spec/foo_spec.rb'))
|
2020-04-22 19:07:51 +05:30
|
|
|
describe 'Foo' do
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'for a non-EE application file' do
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'registers no offenses' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~SOURCE, full_path('app/models/blog_post.rb'))
|
2020-04-22 19:07:51 +05:30
|
|
|
class BlogPost
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'for an EE application file' do
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'registers no offenses' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~SOURCE, full_path('ee/app/models/blog_post.rb'))
|
2020-04-22 19:07:51 +05:30
|
|
|
class BlogPost
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'for an EE spec file for EE only code' do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:spec_file_path) { full_path('ee/spec/controllers/foo_spec.rb') }
|
|
|
|
|
|
|
|
it 'registers no offenses' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~SOURCE, spec_file_path)
|
2020-04-22 19:07:51 +05:30
|
|
|
describe 'Foo' do
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'when there is a duplicate file' do
|
2020-04-22 19:07:51 +05:30
|
|
|
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
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_offense(<<~SOURCE, spec_file_path)
|
2020-04-22 19:07:51 +05:30
|
|
|
describe 'Foo' do
|
|
|
|
^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/ee/foo_spec.rb`.
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'for an EE spec file for EE extension' do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:spec_file_path) { full_path('ee/spec/controllers/ee/foo_spec.rb') }
|
|
|
|
|
|
|
|
it 'registers no offenses' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~SOURCE, spec_file_path)
|
2020-04-22 19:07:51 +05:30
|
|
|
describe 'Foo' do
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'when there is a duplicate file' do
|
2020-04-22 19:07:51 +05:30
|
|
|
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
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_offense(<<~SOURCE, spec_file_path)
|
2020-04-22 19:07:51 +05:30
|
|
|
describe 'Foo' do
|
|
|
|
^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/foo_spec.rb`.
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|