【发布时间】:2015-10-27 20:17:17
【问题描述】:
我有一个方法:
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 而失败?
【问题讨论】: