Rubocop: Parenthesize warning incorrectly identifying method as param

Created on 28 Mar 2017  路  5Comments  路  Source: rubocop-hq/rubocop

the cop identifies the method sort_by as a paramater


Expected behavior

Unknown what the purpose of the cop exactly is

Actual behavior

verify.rb:59:8: W: Parenthesize the param sort_by to make sure that the block will be associated with the != method call. error('section.yml is not alphabetized by name') \ if sections != sections.sort_by { |section| section['id'].downcase } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

git checkout https://github.com/2factorauth/twofactorauth -b 51df6e1 bundle install bundle exec rake

RuboCop version

Using rubocop 0.48.0
bug

Most helpful comment

Thanks for quick answer, in my case I've decided to fix it refactoring to:

expect(deliver).not_to change(GuestListMembership, :count)

But you may consider putting exception I guess... this is looks like common case to me.

All 5 comments

Same mistake happens for common rspec assertions like:

expect(deliver).not_to change { GuestListMembership.count }

Where parenthesize seems also not needed

Where parenthesize seems also not needed

This example is different - it this DSL that's completely fine, but it might have also been an actual oversight. The cop can't possible tell those apart. I'm advising people to simply disable the cop when needed in such cases. Or we can add some method exceptions list. At any rate - that's a different problem.

Thanks for quick answer, in my case I've decided to fix it refactoring to:

expect(deliver).not_to change(GuestListMembership, :count)

But you may consider putting exception I guess... this is looks like common case to me.

As well rubocop raises only with expect().not_to same with expect().to doesn't raise this error.

@dzirtusss I'm seeing the exact same thing here, barks only on expect().not_to

Was this page helpful?
0 / 5 - 0 ratings