Class: RuboCop::Cop::RSpec::FilePath
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::RSpec::FilePath
- Includes:
- RSpec::TopLevelDescribe
- Defined in:
- lib/rubocop/cop/rspec/file_path.rb
Overview
Checks the path of the spec file and enforces that it reflects the described class/module and its optionally called out method.
With the configuration option ‘CustomTransform` modules or clases can be specified that should not as usual be transformed from CamelCase to snake_case (e.g. ’RuboCop’ => ‘rubocop’ ).
Constant Summary collapse
- MESSAGE =
'Spec path should end with `%s`'
- METHOD_STRING_MATCHER =
/^[\#\.].+/
Instance Method Summary collapse
Methods included from RSpec::TopLevelDescribe
Instance Method Details
#on_top_level_describe(node, args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubocop/cop/rspec/file_path.rb', line 23 def on_top_level_describe(node, args) return unless single_top_level_describe? object = const_name(args.first) return unless object path_matcher = matcher(object, args[1]) return if source_filename =~ regexp_from_glob(path_matcher) add_offense(node, :expression, format(MESSAGE, path_matcher)) end |