2
我有一個方法:Rspec:如果最終引發異常,如何測試方法內容?
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
?