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

Lint/AmbiguousBlockAssociation with rspec satisfy #7573

Closed
ShockwaveNN opened this issue Dec 16, 2019 · 2 comments
Closed

Lint/AmbiguousBlockAssociation with rspec satisfy #7573

ShockwaveNN opened this issue Dec 16, 2019 · 2 comments

Comments

@ShockwaveNN
Copy link
Contributor

I'm aware of #4222 issue, but it's pretty old, more complicated and maybe something changed since

Steps to reproduce the problem

  1. Create rspec file with single example from https://relishapp.com/rspec/rspec-expectations/v/3-0/docs/built-in-matchers/satisfy-matcher
RSpec.describe 10 do
  it { is_expected.to satisfy { |v| v > 5 } }
end
  1. rubocop test_spec.rb
    Result is:
test_spec.rb:4:8: W: Lint/AmbiguousBlockAssociation: Parenthesize the param satisfy { |v| v > 5 } to make sure that the block will be associated with the satisfy method call.
  it { is_expected.to satisfy { |v| v > 5 } }

Is there any way to use to satisfy matcher without disabling Lint/AmbiguousBlockAssociation?

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.77.0 (using Parser 2.6.5.0, running on ruby 2.5.7 x86_64-linux)
@buehmann
Copy link
Contributor

Is there any way to use to satisfy matcher without disabling Lint/AmbiguousBlockAssociation?

You can do what the cop suggests. Not sure that you will like the result; usually the to method is used without parentheses in RSpec code.

RSpec.describe 10 do
  it { is_expected.to(satisfy { |v| v > 5 }) }
end

@ShockwaveNN
Copy link
Contributor Author

@buehmann Thanks, that'll do for me, could not figure it out by myself

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

2 participants