Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RSpec/StringAsInstanceDoubleConstant #1957
Add RSpec/StringAsInstanceDoubleConstant #1957
Changes from all commits
324552c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hello! I was looking through the offences this cop turned up in the codebase I work on, and noticed they're identical to those produced by
RSpec/VerifiedDoubleReference
(which we had disabled via TODO file). The docs would suggest they're doing largely the same thing — is there any meaningful difference that could be clarified in the docs?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi!
Nice catch, we’ve missed this completely.
The new cop is essentially the old one, but with no option to select the style. And this is certainly the direction we choose to enforce.
Your input is valuable, why did you decide to turn the cop off?
In a nutshell, we’ve discovered that an instance_double with a string argument does not verify, and behaves identically to a regular
double
. It makes sense to make the usage explicit, and to use adouble
for abstract doubles, andinstant_double
for specific ones, and verify them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't totally turn off
VerifiedDoubleReference
, just ignored a number of existing offences via.rubocop_todo.yml
— it's a large, old codebase, but Rubocop was only added semi-recently. It's definitely a useful cop for the reasons you've outlined!That being said, if this new cop is wholly redundant, then I'll likely turn it off 😅. Would it make sense to deprecate one or the other? For what it's worth,
VerifiedDoubleReference
appears to support e.g.class_double
as well, which I see was a concern raised in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing.
Yes, it would make sense to deprecate one of the cops, and I’d remove the EnforcedStyle: string option from the old one if it is less intrusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thank you for immediately reporting this Luc!
I'm happy to deprecate the new cop and focus on updating the original cop.
So the action items are
StringAsInstanceDoubleConstant
-- is there a way to make it an alias of the other cop?VerifiedDoubleReference
as it is not consistently verifying. Is there a way to deprecate this or do we simply remove it?I'll also take a look if there's anything in the new implementation worth porting over to [VerifiedDoubleReference](https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecverifieddoublereference
I can probably get started on this on Monday. If anyone wants to pitch in or get started earlier, you are by all means welcome to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could have it inherit from
VerifiedDoubleReference
and add the deprecation message, if that makes sense?