Skip to content
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

Regression of #4198 - Lint/AmbiguousBlockAssociation #7486

Open
luke-hill opened this issue Nov 6, 2019 · 11 comments
Open

Regression of #4198 - Lint/AmbiguousBlockAssociation #7486

luke-hill opened this issue Nov 6, 2019 · 11 comments

Comments

@luke-hill
Copy link


Expected behavior

expect { move_direction }.not_to change { current_room_id } should not raise any offenses
expect { move_direction }.to change { current_room_id }.to(new_room_id) should not raise any offenses

Actual behavior

expect { move_direction }.not_to change { current_room_id } raises an offense
expect { move_direction }.to change { current_room_id }.to(new_room_id) does not raise an offense

Steps to reproduce the problem

Code is attached above. I added the working variety to show comparison.

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ [bundle exec] rubocop -V
0.76.0 (using Parser 2.6.5.0, running on ruby 2.6.3 x86_64-linux)
@stale
Copy link

stale bot commented May 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label May 4, 2020
@mvz
Copy link
Contributor

mvz commented May 17, 2020

I'm still seeing this issue in RuboCop 0.83.0.

@stale stale bot removed the stale Issues that haven't been active in a while label May 17, 2020
@kreintjes
Copy link

Still an issue in 0.91.0.

@kreintjes
Copy link

@luke-hill @mvz apparently it is desired behaviour, because the syntax is ambiguous. You can fix it as suggested here: #8732 (comment)

In some cases it might also be possible to write the matches as change(object, :attribute) instead of using a block, as suggested here: #4198 (comment)

Or you can disable the cop in this specific case as suggested by bbatsov here: #4198 (comment)

@luke-hill
Copy link
Author

4198 is impossible here. As I don't have a method on my object output, just the object.

The issue is more than not_to is behaving different to to

@mvz
Copy link
Contributor

mvz commented Nov 2, 2020

This seems to be the same behaviour as mentioned in #4198 (comment). I'm not sure if that was actually ever fixed?

As an aside, maybe change(self, :current_room_id) works?

@reedstonefood
Copy link

If you're on rubocop 1.13 or later, then you can use IgnoreMethods (as mentioned just above this comment) to deal with this scenario. #9685

@jimbali
Copy link

jimbali commented Jul 30, 2021

Can't you just put parantheses around the change method to make it unambiguous?

expect { move_direction }.not_to(change { current_room_id })

@luke-hill
Copy link
Author

Yep that was offered last year by @kreintjes

If someone from the rubocop technical team says this won't be fix then they can close it. I don't think the original method was that bad?

@jimbali
Copy link

jimbali commented Jul 30, 2021

ah ok, so you're just saying that it's not ambiguous? I was thinking that maybe it was somehow ambiguous in the ruby syntax and that putting parentheses makes it explicitly a method call rather than something else, but I'm not sure what else it would be. It seems like perfectly readable Rspec tbf.

@reedstonefood
Copy link

Our example of this is similar.

expect { subject.perform }.to raise_error { |error|
  # some expectation of error
  # another expectation of error
}

This could be fixed as suggested by @jimbali :

expect { subject.perform }.to(raise_error { |error|
  # some expectation of error
  # another expectation of error
})

However, IMO this reduces readability, which I find to be a fantastic feature of rspec. I don't want extra paranthesis above what is there already. We'll be using the IgnoreMethods functionality to stop these being flagged up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants