dream_test/matchers/result
Result matchers for dream_test.
These matchers work with Result(a, e) values and support chaining.
They’re re-exported through dream_test/assertions/should.
Chaining
Both be_ok and be_error extract their inner values, allowing you to
chain additional matchers:
import dream_test/assertions/should.{should, be_ok, be_error, equal, or_fail_with}
// Check that it's Ok, then check the inner value
parse_int("42")
|> should()
|> be_ok()
|> equal(42)
|> or_fail_with("Should parse to 42")
// Check that it's Error, then check the error value
validate(invalid_input)
|> should()
|> be_error()
|> equal(ValidationError("email required"))
|> or_fail_with("Should fail with email error")
Values
pub fn be_error(
value_or_result: types.MatchResult(Result(a, e)),
) -> types.MatchResult(e)
Assert that a Result is Error and extract the error value.
If the assertion passes, the error value is passed to subsequent matchers.
Example
parse_int("not a number")
|> should()
|> be_error()
|> or_fail_with("Should fail to parse")
Chaining
Error("invalid")
|> should()
|> be_error()
|> equal("invalid")
|> or_fail_with("Should be Error with 'invalid'")
pub fn be_ok(
value_or_result: types.MatchResult(Result(a, e)),
) -> types.MatchResult(a)
Assert that a Result is Ok and extract its value.
If the assertion passes, the Ok value is passed to subsequent matchers.
Example
parse_int("42")
|> should()
|> be_ok()
|> or_fail_with("Should parse successfully")
Chaining
Ok("hello")
|> should()
|> be_ok()
|> equal("hello")
|> or_fail_with("Should be Ok with 'hello'")