rspec-rails: "expect to receive with" throws error when switching to Rails 7.1
What Ruby, Rails and RSpec versions are you using?
Ruby version: 3.2.1 Rails version: 7.1.1 RSpec version: 3.12 (rspec-rails 6.0.3)
Observed behaviour
Example spec expect(Worker).to receive(:perform_async).with(param1, param2)
returns ArgumentError: wrong number of arguments (given 2, expected 0)
Switching to deprecated Worker.should_receive(:perform_async).with(param1, param2) passes.
Expected behaviour
Passes with “expect to receive with” syntax.
Can you provide an example app?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (7 by maintainers)
Regarding the initial issue, I am getting the same for every
within my specs after upgrading to Rails 7.1:According to ActiveSupport’s changelog,
Object#withwas added with 7.1.0.beta1:Relevant commit: https://github.com/rails/rails/commit/1884323574b35b3a2286850f3c98f677633728f1
Apparently, you’re passing an empty array splatted, resulting in no arguments to
include, @kashiftariq1997This issue is unrelated. I suggest you to seek further help using https://rspec.info/help, SO, or open a new issue with proper reproduction example.
Please provide a repro and I’ll fix it.
expect(assigns(:documents_to_review)).to_query include(*investment.investor_signature_envelopes.review)
get error: ArgumentError: include() is not supported, please supply an argument
@JonRowe can confirm, 3.12.6 solves the issue, we were still on 3.12.3 👍
Ah this was actually fixed for us by ensuring the rspec-mocks dependency was updated to 3.12.5, rather than only checking that rspec/rspec-rails was up-to-date.
I notice the original issue does not include the rspec-mocks version so it’s possible that it’s the same issue of not noticing the child dependency versions.