-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
RSpec/ReceiveMessages
is marked as a safe autocorrect, but is not
#1677
Comments
This can be solved by autocorrected code to the last position of previous code, not first. would you like to send a PR, @john-h-k ? |
Just ran into the same issue:
|
And another one, of this form:
In this case, it's impossible to to use |
I should be able to confidently run safe rubocop autocorrects without even checking them, and this doesn’t pass that test. Even with the change to reorder the lines better, this is still an inherently unsafe fix |
I don’t have much to add to that. |
I don't mean in a legal sense. I mean that is the attitude taken by the rest of rubocop. Other "safe" autocorrects are ones which have zero effect on the actual behaviour of the program and instead just visual. This affects the behaviour |
Consecutive The following are offenses allow(Foo).to receive(:bar).and_return(1)
allow(Foo).to receive(:cat).and_return(baz) The following are not considered offenses allow(Foo).to receive(:bar).and_return(1)
do_something
allow(Foo).to receive(:cat).and_return(baz) |
I was thinking that for a bit, until I just ran into one of this form:
so... consecutive expectations and none of those expectations' return value makes a call to the receiving object? but what about if it calls some other method, which would then call the receiving object? I think it should just be marked as unsafe, with some of these examples in the docs for why it's unsafe. |
I don’t mean in a legal way. I mean bugs and deficiencies take place, and “should confidently without checking” is an aspiration, but we almost never can make sure. in RuboCop, a cop is safe to auto-correct if it is “by design”, not “by implementation”. This is where bugs and design flaws manifest the difference between the expectation and reality. |
Is the example with using the result of one call as the return value of another realistic? |
I mean, I found it in an actual code base, and it caused my specs to fail until I figured out why. As to if it’s well-written code… that could be up for debate. |
#1687 marks the cop’s autocorrection as unsafe. Reviews are welcome.
Let’s try to do this in a later PR. |
Aside from the fact that
receive_messages
and similar could be overridden (which in my mind means it should never be considered a safe cop), it is unsafe:autocorrects to
The text was updated successfully, but these errors were encountered: