dream_test/matchers/result
Result matchers for dream_test.
These matchers work with Result(a, e) values and are re-exported through
dream_test/matchers.
be_ok() unwraps Ok(value) so you can keep matching on the inner value.
be_error() unwraps Error(value) so you can match on the error value.
Example
Ok("hello")
|> should
|> be_ok()
|> be_equal("hello")
|> or_fail_with("expected Ok(\"hello\")")
Values
pub fn be_error(
value_or_result 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.
This enables chaining like be_error() |> be_equal("...").
Example
Error("nope")
|> should
|> be_error()
|> be_equal("nope")
|> or_fail_with("expected Error(\"nope\")")
Parameters
value_or_result: theMatchResult(Result(a, e))produced byshould(or a previous matcher)
Returns
A MatchResult(e):
- On
Error(value), the chain continues with the unwrapped errorvalue. - On
Ok(_), the chain becomes failed and later matchers are skipped.
pub fn be_ok(
value_or_result 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.
This enables chaining like be_ok() |> be_equal("...").
Example
Ok("hello")
|> should
|> be_ok()
|> be_equal("hello")
|> or_fail_with("expected Ok(\"hello\")")
Parameters
value_or_result: theMatchResult(Result(a, e))produced byshould(or a previous matcher)
Returns
A MatchResult(a):
- On
Ok(value), the chain continues with the unwrappedvalue. - On
Error(_), the chain becomes failed and later matchers are skipped.