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 syntax #4222

Closed
morgoth opened this issue Mar 31, 2017 · 2 comments
Closed

Lint/AmbiguousBlockAssociation with Rspec syntax #4222

morgoth opened this issue Mar 31, 2017 · 2 comments

Comments

@morgoth
Copy link

morgoth commented Mar 31, 2017

I'm quite lost with this example:

expect do
  make_request
end.to enqueue_job(DeliverEventWebhookJob)
  .with { |event_name, _claim_id| expect(event_name).to eq("claim_renewed") }

The offence is:

W: Lint/AmbiguousBlockAssociation: Parenthesize the param with to make sure that the block will be associated with the to method call.
    expect do ...
    ^^^^^^^^^

I tried few other ways, but either Rubocop is not happy or it's not a valid Ruby syntax.

$ rubocop -V
0.48.0 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-linux)
@Drenmi
Copy link
Collaborator

Drenmi commented Mar 31, 2017

I would probably recommend disabling this cop for specs, since it's a deliberate idiom in RSpec. 🙂

Lint/AmbiguousBlockAssociation:
  Exclude:
    - "spec/**/*"

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 31, 2017

Exactly.

@bbatsov bbatsov closed this as completed Mar 31, 2017
koppen added a commit to substancelab/dotfiles that referenced this issue May 26, 2017
Rubocop 0.48 introduced a new Lint/AmbiguousBlockAssocation cop [1], which
guards against the issues detailed in
rubocop/rubocop#3931.

However, the pattern is a solid RSpec idiom and not likely to cause the problems
Lint/AmbigiousBlockAssociation attempts to guard against. For example:

    expect { foo }.to change { bar }

so we'll just ignore it in RSpec as suggested in
rubocop/rubocop#4222.

[1]: https://github.com/bbatsov/rubocop/blob/d1b9d66c3518389b0c408a6a4a42061b36748df4/relnotes/v0.48.0.md
sebabeceiro added a commit to icariohealth/ruby-novu-code-style that referenced this issue Jan 25, 2018
instructure-gerrit pushed a commit to instructure/canvas-lms that referenced this issue Feb 12, 2018
also fix a typo in .eslintignore caused by cae5d84

motivation:
rubocop/rubocop#4222 (comment)

this is a deliberate idiom in rspec, so let's update .robocop.yml to
match rubocop's own config

closes: GRADE-841

test plan: specs pass

Change-Id: I534eabe48fb227b6fa7b425502e645f22b1a51f3
Reviewed-on: https://gerrit.instructure.com/140424
Tested-by: Jenkins
Reviewed-by: Keith T. Garner <kgarner@instructure.com>
Product-Review: Derek Bender <djbender@instructure.com>
QA-Review: Derek Bender <djbender@instructure.com>
scmx added a commit to standout/Coding that referenced this issue Mar 27, 2018
Lint/AmbiguousBlockAssociation: Parenthesize the param change { ... } to
make sure that the block will be associated with the change method call.

rubocop/rubocop#4222
bwebster added a commit to kapost/codeclimate-common that referenced this issue Apr 30, 2018
- With our current config, we get a lot of linter errors from code
  that looks like this:
    expect { ... }.to change { MyModel.count }
  The linter error looks like this:
    Parenthesize the param `change { MyModel.count }` to make sure
    that the block will be associated with the `change` method call.
  This is rspec syntax and should not be flagged as a linter issue.
- See rubocop/rubocop#4222
drn added a commit to drn/style-guide that referenced this issue Jun 28, 2018
drn added a commit to drn/style-guide that referenced this issue Jun 28, 2018
leeky added a commit to Crown-Commercial-Service/DataSubmissionServiceAPI that referenced this issue Jul 26, 2018
If a supplier or agreement already exists, retrieve it rather than
creating a brand new one.

Added RuboCop exclusion for Lint/AmbiguousBlockAssociation, as per
recommmendation: rubocop/rubocop#4222
leeky added a commit to Crown-Commercial-Service/DataSubmissionServiceAPI that referenced this issue Jul 26, 2018
If a supplier or agreement already exists, retrieve it rather than
creating a brand new one.

Added RuboCop exclusion for Lint/AmbiguousBlockAssociation, as per
recommmendation: rubocop/rubocop#4222
indocomsoft added a commit to nussucommit/takoyaki that referenced this issue Nov 14, 2018
indocomsoft added a commit to nussucommit/takoyaki that referenced this issue Nov 14, 2018
indocomsoft added a commit to nussucommit/takoyaki that referenced this issue Nov 14, 2018
* Prevent unauthenticated users from signing up

* Disable cop complaining about rspec idiom

Refer to rubocop/rubocop#4222

* Fix style violation

* Change authorization mc -> admin following UserController
emileswarts added a commit to alphagov/govwifi-user-signup-api that referenced this issue Jan 2, 2019
This is the glue required to run the use cases.

The Rubocop ignore syntax is due to this.
rubocop/rubocop#4222
emileswarts added a commit to alphagov/govwifi-user-signup-api that referenced this issue Jan 2, 2019
This is the glue required to run the use cases.

The Rubocop ignore syntax is due to this.
rubocop/rubocop#4222
emileswarts added a commit to alphagov/govwifi-user-signup-api that referenced this issue Jan 2, 2019
This is the glue required to run the use cases.

The Rubocop ignore syntax is due to this.
rubocop/rubocop#4222
emileswarts added a commit to alphagov/govwifi-user-signup-api that referenced this issue Jan 2, 2019
* Add obfusticate user details functionality

This used to be done by a lambda written in Python.
We've since decided that all cron tasks will be run as ECS scheduled
tasks.

This still needs to be invoked through a rake task.

* Create Rake tasks for deleting user details

This is the glue required to run the use cases.

The Rubocop ignore syntax is due to this.
rubocop/rubocop#4222
VegaFromLyra added a commit to VegaFromLyra/dev.to that referenced this issue Jan 26, 2020
* Sidekiq version of delayed job and updating services that used the
delayed job
* Intentionally removed the defensive check in the sidekiq version. If
the episode is missing and there's worker scheduled to update it's media
url then that reveals a bug elsewhere and should fail fast instead of
skipping ahead.
* Also excluded the ambiguous block rule for rspecs since that
conflicts with the rspec `expect` block, found that recommentation
thanks to rubocop/rubocop#4222 (and rubocop
was complaining about this in the pre-commit hook for these changes)
Mifrill added a commit to Mifrill/thread_safe_uniqueness_record that referenced this issue Oct 30, 2020
skelz0r added a commit to etalab/admin_api_entreprise that referenced this issue Aug 25, 2022
skelz0r added a commit to etalab/admin_api_entreprise that referenced this issue Aug 25, 2022
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

3 participants