我有一个方法,其中有一个开始/救援块。如何使用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