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

RSpec/ExpectChange mixes value expectation targets and block expectation syntax #814

Closed
pirj opened this issue Aug 21, 2019 · 0 comments · Fixed by #816
Closed

RSpec/ExpectChange mixes value expectation targets and block expectation syntax #814

pirj opened this issue Aug 21, 2019 · 0 comments · Fixed by #816

Comments

@pirj
Copy link
Member

pirj commented Aug 21, 2019

The current cop is quite puzzling to me, especially its docs and specs.

Trying to reproduce the syntax, but it fails for me:

  it do
    expect(1).to change { rand }
  end
     Failure/Error: expect(1).to change { rand }
       expected `rand` to have changed, but was not given a block

How does it work?

change is a block matcher, but all the specs and examples use the value expectation target.

The only idea is the use of implicit block expectation target, which is discouraged to use and for which we have an RSpec/ImplicitBlockExpectation.

Should we change specs and examples?

pirj added a commit to pirj/rubocop-rspec that referenced this issue Aug 22, 2019
`expect(run)` is not a valid target for `change` matcher unless one uses
the obscure implicit block expectation

    subject(:run) { -> { do_something } }

Fixes rubocop#814
kellysutton pushed a commit to kellysutton/rubocop-rspec that referenced this issue Oct 28, 2019
`expect(run)` is not a valid target for `change` matcher unless one uses
the obscure implicit block expectation

    subject(:run) { -> { do_something } }

Fixes rubocop#814
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

Successfully merging a pull request may close this issue.

1 participant