How to check what is queued in ActiveJob using Rspec

后端 未结 7 1221
感动是毒
感动是毒 2021-01-31 08:33

I\'m working on a reset_password method in a Rails API app. When this endpoint is hit, an ActiveJob is queued that will fire off a request to Mandrill (our transactional email c

7条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 09:06

    Rspec 3.4 now has have_enqueued_job cooked in, which makes this a lot easier to test:

    it "enqueues a YourJob" do
      expect {
        get :your_action, {}
      }.to have_enqueued_job(YourJob)
    end
    

    it has other niceties for have_enqueued_job to allow you to check the argument(s) and the number of times it should be queued up.

提交回复
热议问题