2019-07-29 15:27:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 18:10:07 +00:00
|
|
|
require 'rubocop_spec_helper'
|
2019-07-29 15:27:36 +00:00
|
|
|
require_relative '../../../../rubocop/cop/rspec/top_level_describe_path'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::RSpec::TopLevelDescribePath do
|
2019-07-29 15:27:36 +00:00
|
|
|
context 'when the file ends in _spec.rb' do
|
|
|
|
it 'registers no offenses' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_no_offenses(<<~SOURCE, 'spec/foo_spec.rb')
|
2019-07-29 15:27:36 +00:00
|
|
|
describe 'Foo' do
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the file is a frontend fixture' do
|
|
|
|
it 'registers no offenses' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_no_offenses(<<~SOURCE, 'spec/frontend/fixtures/foo.rb')
|
2019-07-29 15:27:36 +00:00
|
|
|
describe 'Foo' do
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the describe is in a shared example' do
|
|
|
|
context 'with shared_examples' do
|
|
|
|
it 'registers no offenses' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
|
2019-07-29 15:27:36 +00:00
|
|
|
shared_examples 'Foo' do
|
|
|
|
describe '#bar' do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with shared_examples_for' do
|
|
|
|
it 'registers no offenses' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
|
2019-07-29 15:27:36 +00:00
|
|
|
shared_examples_for 'Foo' do
|
|
|
|
describe '#bar' do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the describe is at the top level' do
|
|
|
|
it 'marks the describe as offending' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_offense(<<~SOURCE, 'spec/foo.rb')
|
2019-07-29 15:27:36 +00:00
|
|
|
describe 'Foo' do
|
|
|
|
^^^^^^^^^^^^^^ #{described_class::MESSAGE}
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|