Coder Social home page Coder Social logo

Comments (17)

vrinek avatar vrinek commented on June 16, 2024 4

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 block

    client.timeout # => 5
    client.with(timeout: 1) do
      client.timeout # => 1
    end
    client.timeout # => 5

Relevant commit: rails/rails@1884323

from rspec-rails.

fsuchan avatar fsuchan commented on June 16, 2024 1

@JonRowe can confirm, 3.12.6 solves the issue, we were still on 3.12.3 👍

from rspec-rails.

pirj avatar pirj commented on June 16, 2024

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.

fsuchan avatar fsuchan commented on June 16, 2024

@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.

pirj avatar pirj commented on June 16, 2024

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.

StanBright avatar StanBright commented on June 16, 2024

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.

pirj avatar pirj commented on June 16, 2024

@StanBright i suggest you to yse ‘and_wrap_original’ and to figure out what makes the second call.

from rspec-rails.

StanBright avatar StanBright commented on June 16, 2024

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.

pirj avatar pirj commented on June 16, 2024

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.

byroot avatar byroot commented on June 16, 2024

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.

justisb avatar justisb commented on June 16, 2024

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#withpatch 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.

justisb avatar justisb commented on June 16, 2024

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.

JonRowe avatar JonRowe commented on June 16, 2024

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.

vimalloc avatar vimalloc commented on June 16, 2024

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.

byroot avatar byroot commented on June 16, 2024

@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.

vimalloc avatar vimalloc commented on June 16, 2024

@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.

byroot avatar byroot commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.