Rspec-rails: undefined method `exactly' for #<RSpec::ActiveJob::Matchers::EnqueueA ..

Created on 1 Apr 2020  ·  3Comments  ·  Source: rspec/rspec-rails

What Ruby, Rails and RSpec versions are you using?

bundle exec ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
bundle exec rails --version
Rails 6.0.2.2
bundle exec rspec --version
RSpec 3.9
  - rspec-core 3.9.1
  - rspec-expectations 3.9.1
  - rspec-mocks 3.9.1
  - rspec-rails 4.0.0
  - rspec-support 3.9.2

Observed behaviour

     Failure/Error: expect(::RedactedJob).to have_been_enqueued.exactly(2).times

     NoMethodError:
       undefined method `exactly' for #<RSpec::ActiveJob::Matchers::EnqueueA:0x00007feb2aa89d10>
     # ./spec/redacted/enqueue_jobs_spec.rb:37:in `block (3 levels) in <module:Redacted>'

Expected behaviour

The 4.0 documentation has the following example, so I expected exactly to be defined.

      UploadBackupsJob.perform_later('backup')
      expect(UploadBackupsJob).to have_been_enqueued.exactly(:once)

Workaround

expect(::RedactedJob).to have_been_enqueued.times(2)

Can you provide an example app?

Happy to, if determined to be needed.

Most helpful comment

Can you please set a breakpoint and check what is the source of the class an instance of which have_been_enqueued returns?

undefined method `exactly' for #<RSpec::ActiveJob::Matchers::EnqueueA:0x00007feb2aa89d10>

RSpec::ActiveJob::Matchers::EnqueueA doesn't look too similar to RSpec::Rails::Matchers::ActiveJob::HaveBeenEnqueued.

Pretty sure you are using rspec-activejob. It's high time to start using rspec-rails's matchers instead.

All 3 comments

Can you please set a breakpoint and check what is the source of the class an instance of which have_been_enqueued returns?

undefined method `exactly' for #<RSpec::ActiveJob::Matchers::EnqueueA:0x00007feb2aa89d10>

RSpec::ActiveJob::Matchers::EnqueueA doesn't look too similar to RSpec::Rails::Matchers::ActiveJob::HaveBeenEnqueued.

Pretty sure you are using rspec-activejob. It's high time to start using rspec-rails's matchers instead.

Pretty sure you are using rspec-activejob. It's high time to start using rspec-rails's matchers instead.

Thanks Phil, after uninstalling rspec-activejob, I can now use exactly.

Good to know @jaredbeck, happy to help 🙌

Was this page helpful?
0 / 5 - 0 ratings