我有一個方法,其中有一個開始/救援塊。如何使用RSpec2測試救援塊?使用RSpec我如何測試救援異常塊的結果
class Capturer
def capture
begin
status = ExternalService.call
return true if status == "200"
return false
rescue Exception => e
Logger.log_exception(e)
return false
end
end
end
describe "#capture" do
context "an exception is thrown" do
it "should log the exception and return false" do
c = Capturer.new
success = c.capture
## Assert that Logger receives log_exception
## Assert that success == false
end
end
end
僅供參考[爲什麼在Ruby中拯救Exception => e'不好的樣式](https://stackoverflow.com/q/10048173/211563)。 – 2014-04-03 00:04:50