debian-mirror-gitlab/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb

64 lines
1.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/top_level_describe_path'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::RSpec::TopLevelDescribePath, type: :rubocop do
2019-10-12 21:52:04 +05:30
include CopHelper
subject(:cop) { described_class.new }
context 'when the file ends in _spec.rb' do
it 'registers no offenses' do
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~SOURCE, 'spec/foo_spec.rb')
2019-10-12 21:52:04 +05:30
describe 'Foo' do
end
SOURCE
end
end
context 'when the file is a frontend fixture' do
it 'registers no offenses' do
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~SOURCE, 'spec/frontend/fixtures/foo.rb')
2019-10-12 21:52:04 +05:30
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-06-23 00:09:42 +05:30
expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
2019-10-12 21:52:04 +05:30
shared_examples 'Foo' do
describe '#bar' do
end
end
SOURCE
end
end
context 'with shared_examples_for' do
it 'registers no offenses' do
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
2019-10-12 21:52:04 +05:30
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-06-23 00:09:42 +05:30
expect_offense(<<~SOURCE, 'spec/foo.rb')
2019-10-12 21:52:04 +05:30
describe 'Foo' do
^^^^^^^^^^^^^^ #{described_class::MESSAGE}
end
SOURCE
end
end
end