rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

RSpec/FilePath cop is completely skipped on routing specs, or specs that don't describe a constant

Open tom-lord opened this issue 4 years ago • 1 comments

See: https://github.com/rubocop-hq/rubocop-rspec/blob/137dc91ba422d701eed88a121275dbdec182a180/lib/rubocop/cop/rspec/file_path.rb#L75-L79

For example, consider the following:

# spec/requests/bad_filename_format.rb

RSpec.describe "Some really cool tests" do
  # ...
end

Because a constant was not defined (i.e. the test description is just a String), the cop is skipped (passes).

However, it still would have been helpful to raise a cop offense here because the filename does not end with _spec.rb.

Likewise, the same thing happens for routing specs - rather than merely relaxing the filename rules for such tests, this cop is completely skipped.

tom-lord avatar Nov 02 '20 15:11 tom-lord

Good catch, thanks for bringing this up. 👍

I guess the cop should be split into the one that suggests a better file name basing on the constant name, and that reports all other file name oddities, not in regards to the constant described.

Do you think you could tackle that? There's a 2.0 release that we're preparing, and now is the best moment to split those two cops. Otherwise, we'll have to split and keep all three cops around, two new pending ones and one old deprecated, up until 3.0.

pirj avatar Nov 02 '20 17:11 pirj

I see that part of the issue has been corrected by https://github.com/rubocop/rubocop-rspec/pull/1441 .

ydah avatar Aug 14 '23 07:08 ydah

However, dividing these into two cops seems like a good and I will try to work on it. It would be good if "the test description is just a String" could also be addressed.

ydah avatar Aug 14 '23 07:08 ydah