Class: RuboCop::Cop::RSpec::FilePath
- Includes:
- RSpec::TopLevelDescribe
- Defined in:
- lib/rubocop/cop/rspec/file_path.rb
Overview
Checks that spec file paths are consistent with the test subject.
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 ‘IgnoreMethods` the called out method will be ignored when determining the enforced path.
With the configuration option ‘CustomTransform` modules or classes can be specified that should not as usual be transformed from CamelCase to snake_case (e.g. ’RuboCop’ => ‘rubocop’ ).
Constant Summary collapse
- MSG =
'Spec path should end with `%<suffix>s`.'
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods included from RSpec::TopLevelDescribe
Methods inherited from Cop
Instance Method Details
#on_top_level_describe(node, args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubocop/cop/rspec/file_path.rb', line 52 def on_top_level_describe(node, args) return unless const_described?(node) && single_top_level_describe? return if routing_spec?(args) glob = glob_for(args) return if filename_ends_with?(glob) add_offense( node, location: :expression, message: format(MSG, suffix: glob) ) end |