Ho un metodo che contiene un blocco di avvio/salvataggio. Come posso testare il blocco di salvataggio usando RSpec2?Utilizzo di RSpec Come posso testare i risultati di un blocco di eccezioni di salvataggio
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 vedere [Perché lo stile è scorretto per 'salvare Eccezione => e' in Ruby?] (Https://stackoverflow.com/q/10048173/211563). –