我有一个方法:
def post
...
if res.failed?
SlackNotifier.notify("Failed", { :channel => "#bugs" })
raise "Boom"
end
res
end
在rspec中我试图对此进行测试,但它失败了RuntimeError
,因为该方法最终会引发异常:
it 'posts to slack' do
allow(SlackNotifier).to receive(:notify)
subject.post
expect(SlackNotifier).to have_received(:notify).with("Failed", { :channel => "#bugs" })
end
我如何阻止它因raise
而失败?
答案 0 :(得分:1)
对该主题进行了解雇加固:
allow(subject).to receive(:raise)