workhorsy / BDD

Behavior Driven Development testing framework for the D programming language
Boost Software License 1.0
3 stars 1 forks source link

shouldThrow should show the expected message on failure #7

Closed workhorsy closed 3 years ago

workhorsy commented 3 years ago

When shouldThrow fails from the wrong exception, we don't get to see what the message actually was.

unittest {
    Throwable ex = null;
    try {
        shouldThrow(delegate() {
            throw new Exception("Kablam!");
        }, "Smack!");
    } catch (Throwable exception) {
        ex = exception;
    }

    ex.shouldNotBeNull();

    // FIXME: We have no idea what the message actually was
    ex.msg.shouldEqual("Exception was thrown. But expected: Smack!");

    // Change it to
    ex.msg.shouldEqual("Exception was thrown. Expected <Smack!> but got <Kablam!>");
}