Class: RuboCop::Cop::RSpec::SpecFilePathSuffix

Inherits:
Base
  • Object
show all
Includes:
FileHelp, TopLevelGroup
Defined in:
lib/rubocop/cop/rspec/spec_file_path_suffix.rb

Overview

Checks that spec file paths suffix are consistent and well-formed.

Examples:

# bad
my_class/foo_specorb.rb   # describe MyClass
spec/models/user.rb       # describe User
spec/models/user_specxrb  # describe User

# good
my_class_spec.rb          # describe MyClass

# good - shared examples are allowed
spec/models/user.rb       # shared_examples_for 'foo'

Constant Summary collapse

MSG =
'Spec path should end with `_spec.rb`.'

Instance Method Summary collapse

Methods included from FileHelp

#expanded_file_path

Methods included from TopLevelGroup

#on_new_investigation, #top_level_groups

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Instance Method Details

#on_top_level_example_group(node) ⇒ Object



26
27
28
29
30
# File 'lib/rubocop/cop/rspec/spec_file_path_suffix.rb', line 26

def on_top_level_example_group(node)
  example_group?(node) do
    add_global_offense(MSG) unless correct_path?
  end
end