What's the best way to test delayed_job chains with rSpec?

大憨熊 提交于 2019-12-03 11:15:26

We can just have one more line in the before block as following:

CommentMailer.stub(:delay).and_return(CommentMailer)

Then you then can have the normal mock check as following:

CommentMailer.should_receive(:deliver_comments).with(comment, true)
Jared

Here are some discussions about chaining methods in rSpec that I found helpful:

Stubbing Chained Methods with Rspec

http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2390b0#

describe '#perform' do
    subject do
      Delayed::Worker.delay_jobs = false
      proc { worker.perform() }
    end

    it { is_expected.to change { ActionMailer::Base.deliveries.length }.by(2) }
  end

Set delayed job as false and u can test it like simple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!