Rails/Rspec: Testing delayed_job mails

前端 未结 5 813
你的背包
你的背包 2021-02-01 17:37

Just wondering how to test that actionmailer requests are actually sent to the delayed_job que in rspec.

I would have assumed it was quite simple, but my delayed_job que

5条回答
  •  失恋的感觉
    2021-02-01 18:00

    I think your mock object is somehow introducing an error -- it's hard to tell exactly how without seeing the definition of the mock_contact method.

    In any case, you might try something along these lines:

      it "queues mail when a contact is created" do
        Contact.stub(:new) { mock_model(Contact,:save => true) }
        Delayed::Job.count.should == 0
        post :create, {}
        Delayed::Job.count.should == 1
      end
    

    or the sexier version (caveat: I always end up doing it the non-sexy way):

      it "queues mail when a contact is created" do
        Contact.stub(:new) { mock_model(Contact,:save => true) }
        expect {
          post :create, {}
        }.to change(Delayed::Job.count).by(1)
      end
    

提交回复
热议问题