rubocop / rubocop-rspec

Code style checking for RSpec files.
https://docs.rubocop.org/rubocop-rspec
MIT License
811 stars 276 forks source link

Incorrect autocorect for RSpec/StringAsInstanceDoubleConstant #1965

Open jcoyne opened 1 month ago

jcoyne commented 1 month ago

When I run the autocorrect for RSpec/StringAsInstanceDoubleConstant, it just changes the string to a constant. However, this constant doesn't exist. It would be better to just say it's not autocorrectable, or just make it a double (not instance_double)

-      let(:api_response) { instance_double('Response', status: 204, content_type: :json) }
+      let(:api_response) { instance_double(Response, status: 204, content_type: :json) }
pirj commented 2 weeks ago

We plan to remove this cop as it duplicates another cop.

As you point out, if the constant is fake, the correction should be to use double.

Do you have issues with the other cop? We were discussing the removal of “string” as a valid enforced style. Do you happen to use it? Would you agree to this?

jcoyne commented 2 weeks ago

My major concern is that it's not auto-correctable. I don't think even unsafe autocorrect should be attempted. I do think prohibiting any non-constant should be flagged on instance_double though.