2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
require 'rubocop/cop/rspec/base'
|
|
|
|
require 'rubocop/cop/rspec/mixin/top_level_group'
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module RSpec
|
2022-11-25 23:54:43 +05:30
|
|
|
class TopLevelDescribePath < RuboCop::Cop::RSpec::Base
|
|
|
|
include RuboCop::Cop::RSpec::TopLevelGroup
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
MESSAGE = 'A file with a top-level `describe` must end in _spec.rb.'
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def on_top_level_example_group(node)
|
2019-10-12 21:52:04 +05:30
|
|
|
return if acceptable_file_path?(processed_source.buffer.name)
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
add_offense(node.send_node, message: MESSAGE)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def acceptable_file_path?(path)
|
2020-11-24 15:15:51 +05:30
|
|
|
File.fnmatch?('*_spec.rb', path) || File.fnmatch?('*/frontend/fixtures/*', path) || File.fnmatch?('*/docs_screenshots/*_docs.rb', path)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|