这是我的情况:
更新AR对象后,它将使用Resque触发一堆后台作业。在我的规范中,我模拟了对Resque#enqueue的调用,类似于以下内容:
it 'should be published' do
# I need to setup these mocks in many places where I want to mock a specific call to Resque, otherwise it fails
Resque.should_receive(:enqueue).with(NotInterestedJob1, anything)
Resque.should_receive(:enqueue).with(NotInterestedJob2, anything)
Resque.should_receive(:enqueue).with(NotInterestedJob3, anything)
# I'm only interested in mocking this Resque call.
Resque.should_receive(:enqueue).with(PublishJob, anything)
end
如您所见,每次我想模拟特定的调用时,我都需要模拟对Resque#enqueue的所有其他调用,有没有办法只模拟一个自定义调用而忽略具有不同参数的其他调用?
提前致谢 ;)
我认为在这种情况下,您将需要做我认为与方法类似的方法as_null_object
,但是在这种情况下,该方法专门用于Resque.enqueue
您不关心的调用:
it 'should be published' do
allow(Resque).to receive(:enqueue) # stub out this message entirely
expect(Resque).to receive(:enqueue).with(PublishJob, anything)
call_your_method.that_calls_enqueue
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句