Comments (17)
Regarding the initial issue, I am getting the same for every with
in my specs after upgrading to Rails 7.1:
ArgumentError:
wrong number of arguments (given 2, expected 0)
# /usr/local/bundle/gems/activesupport-7.1.1/lib/active_support/core_ext/object/with.rb:24:in `with'
# ./spec/lib/mail_configurator_spec.rb:43:in `block (4 levels) in <top (required)>'
# /usr/local/bundle/gems/webmock-3.14.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
According to ActiveSupport's changelog, Object#with
was added with 7.1.0.beta1:
Add
Object#with
to set and restore public attributes around a blockclient.timeout # => 5 client.with(timeout: 1) do client.timeout # => 1 end client.timeout # => 5
Relevant commit: rails/rails@1884323
from rspec-rails.
@JonRowe can confirm, 3.12.6 solves the issue, we were still on 3.12.3 👍
from rspec-rails.
Can you reproduce it with a regular object?
What is the backtrace? Can you set a breakpoint and see what method is called with two arguments, which doesn’t really accept any?
Is that a Sidekiq worker Worker?
from rspec-rails.
@pirj yes, that's a Sidekiq worker 👍
Full example that worked on Rails 7.0 but not on 7.1:
it 'sends an email' do
user = Fabricate(:user, encrypted_password: nil)
expect(EmailWorker).to receive(:perform_async).with('UserInvite::Email', user.id)
Invite::Create.call(user:)
end
from rspec-rails.
Can you please share your invite::Create.call?
Can you make a reproducible example? Check our snippets directory for examples.
Were you able to identify the method that it complains about?
from rspec-rails.
I have a possibly relevant issue with the same gem/ruby versions. It does not fail with ArgumentError.
However, it carries the stub/expectation through different examples and fails with a multiple calls error:
Failure/Error: expect(ListSubscriptionMailer).to receive(:email_confirmation).and_return(mock_mail)
(ListSubscriptionMailer (class)).email_confirmation(*(any args))
expected: 1 time with any arguments
received: 2 times with any arguments
from rspec-rails.
@StanBright i suggest you to yse ‘and_wrap_original’ and to figure out what makes the second call.
from rspec-rails.
The second call is coming from a different spec case. The specs are run randomly, and it fails randomly - i.e. if the spec with the mocked expectation is run before the other case, there's no error.
The same mocking works fine on Rails 7.0 projects. Seemingly, there's something odd with Rspec and Rails 7.1.
from rspec-rails.
Thanks for digging that, @vrinek
The problem is here then
‘’’
next if own_methods.include?(method)
‘’’
https://github.com/rspec/rspec-mocks/blob/868bf98d2aae5f0db15441a41b86b5f9346a12dd/lib/rspec/mocks/matchers/receive.rb#L60
We have a fix for this already, but it doesn’t work somehow rspec/rspec-mocks@a2af97d
Cc @byroot
from rspec-rails.
If someone share a reproduction script or repo, I'll happily debug this. But right now the repro steps are too blurry for me to investigate.
from rspec-rails.
On Rails 7.1 any test that uses the expect(x).to receive(:foo).with('bar')
pattern will break because Rails introduced their own Object#with
patch in ActiveSupport that interferes with the RSpec with
method: https://github.com/rails/rails/blob/7-1-stable/activesupport/lib/active_support/core_ext/object/with.rb
See comment below.
from rspec-rails.
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.
from rspec-rails.
There was a patch kindly provided by byroot in rspec-mocks 3.12.5 (current is 3.12.6) @fsuchan what version of rspec-mocks are you running?
from rspec-rails.
I'm running into this exact issue, except it's not rspec-mocks, but instead it's happening with a define_negated_matcher
, and as an example ,enqueue_job
:
RSpec::Matchers.define_negated_matcher(:not_enqueue_job, :enqueue_job)
it 'does not enqueue a job' do
expect { 'Foo'.downcase }.to not_enqueue_job.with('Bar')
end
I think we have a few custom matchers that run into this issue too.
I'm gonna open an issue on the rails repo to see what they say, but I wanted to bring this up here as well!
Cheers.
from rspec-rails.
@vimalloc I suspect not_enqueue_job
is in something like rspec-rails, better open your issue there. You can tag me as well, I'll have a look if I can.
from rspec-rails.
@byroot thank you! I have an issue with a lot more details here, if you want to look at it! rails/rails#49958
from rspec-rails.
I provided a workaround on the Rails issue, and started working on a fix at rspec/rspec-expectations#1434.
If there is a maintainer that could approve CI so I can see what need to be fixed for very old rubies I can't run on my machine, that would be much appreciated.
from rspec-rails.
Related Issues (20)
- Allow erb extension for template files HOT 1
- `url_for` fails to generate route with using `resource` method in config/routes.rb HOT 3
- Rails 7.1.beta.1: second test failure on system specs HOT 4
- rails 7.1 stub_template issue: undefined method `unshift' for #<ActionView::PathSet HOT 4
- Wrong variable name when generate scaffold with namespace & model-name options HOT 1
- Providing JSON data no longer works in request specs with Rails 7.1 HOT 6
- Template stubs are not removed in Rails 7.1. HOT 4
- Rails 7.1 hangs in github actions when use_transactional_fixtures = true HOT 7
- Rails/RedundantActiveRecordAllMethod false positive HOT 1
- Rails 7.1 upgrade: using deprecated preview_path= HOT 3
- Rails 7.1 raise WrongScopeError on take_failed_screenshot HOT 3
- be_routable not working in controller spec with Rails 7.1 HOT 2
- Wrap examples with Rails executor HOT 2
- Fixtures for namespaced models don't seem to work in rspec-rails 6.1.0 HOT 6
- Even if specify the use of TestUnit, it will be overwritten by Minitest and cannot be used. HOT 6
- stub_template isn't working as expected on latest version HOT 1
- render_template is not working HOT 12
- View example group inserts controller path into lookup_context in the wrong order HOT 2
- :git => "git://github.com/rspec/rspec.git" Not working anymore HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rspec-rails.