Başla/kurtarma bloğu olan bir yöntem var. Kurtarma bloğunu RSpec2 kullanarak nasıl test edebilirim?RSpec'i kullanma Kurtarma istisnası bloğunun sonuçlarını nasıl test edebilirim
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
FYI, [Neden Ruby'de istisna kurtarma için kötü bir stile neden oluyor?] (Https://stackoverflow.com/q/10048173/211563). –