assert_fail

Macro assert_fail 

Source
macro_rules! assert_fail {
    ($call:expr) => { ... };
    ($call:expr, $msg:expr) => { ... };
}
Expand description

Assert that a function call fails, returning the error value

Convenience macro for testing error paths. Calls the function and asserts it returns Err, then returns the error value for further assertions.

Ergonomics: With test! macro’s new Result return type support, this provides a concise way to test error cases without intermediate variables.

§Example

use chicago_tdd_tools::{assert_fail, test};

test!(test_should_fail, {
    // Arrange: Function that should fail

    // Act & Assert: Verify function fails and extract error
    let error = assert_fail!(fallible_function());
    assert_eq!(error, "error");
});

§Example with custom message

use chicago_tdd_tools::{assert_fail, test};

test!(test_should_fail_with_msg, {
    // Act & Assert: Verify function fails with custom message
    let error = assert_fail!(fallible_function(), "Operation should fail");
    assert_eq!(error, "error");
});