From 0aa96c799ae64f0cfae1d775d0e29bdb8514ff4a Mon Sep 17 00:00:00 2001 From: Bryan Mulvihill Date: Sun, 31 Dec 2017 13:26:38 -0500 Subject: [PATCH] [spec] Fix generic expect_raises --- stdlib/spec/single_spec.mt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stdlib/spec/single_spec.mt b/stdlib/spec/single_spec.mt index cd30103..796e8a2 100644 --- a/stdlib/spec/single_spec.mt +++ b/stdlib/spec/single_spec.mt @@ -44,9 +44,14 @@ defmodule Spec # a specific error. def expect_raises(&block) block() - raise %AssertionFailure{@name, expected_error, "no error"} + raise %AssertionFailure{@name, "Any Error", "no error"} + rescue ex : AssertionFailure + # Rescuing an AssertionFailure implies that `block` did + # not raise an exception, so the exception is re-raised. + raise ex rescue - # If an error was raised, the assertion passes. + # Otherwise, the error must have come from `block`, so the + # assertion is successful. end end end