Skip to content

RSpec/SpecFilePathFormat false negatives #2167

@Epigene

Description

@Epigene

RSpec/SpecFilePathFormat cop is far too permissive when it comes to namespace/postfix discrepencies in spec files.


Steps to reproduce the problem

Configure rubocop-rspec

RSpec/SpecFilePathFormat:
  Enabled: true

Set up a vanilla Rails project with at least a single model, say User.
Set up a completely wrong spec file

# in spec/models/random/userx_spec.rb
RSpec.describe User, type: :model do 
end

Expected behavior

File is flagged as invalid, saying its placement and naming imply Random::Userx class to be specced, but User is being specced.

Actual behavior

No offence is reported.

RuboCop RSpec version

$ [bundle exec] rubocop -V
rubocop -V
1.86.0 (using Parser 3.3.10.2, Prism 1.9.0, parser_prism, rubocop-ast 1.49.1, analyzing as Ruby 3.4, running on ruby 3.4.8) [arm64-darwin23]
  - rubocop-capybara 2.22.1
  - rubocop-factory_bot 2.28.0
  - rubocop-rails 2.34.3
  - rubocop-rspec 3.8.0
  - rubocop-rspec_rails 2.32.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions