expect abstract method

void expect(
  1. Iterable<String> clause(),
  2. Rejection? predicate(
    1. T
    )
)

Expect that predicate will not return a Rejection for the checked value.

The clause callback returns a description of what is checked which stands on its own. For instance the is equal to <1> in:

Expected: a int that:
  is equal to <1>

Description callbacks return an Iterable<String> where each element is a line in the output. Individual elements should not contain newlines. Utilities such as prefixFirst, postfixLast, and literal may be useful to format values which are potentially multiline.

The description of an expectation may never be shown to the user, so the callback may never be invoked. If all the conditions on a subject succeed, or if the failure detail for a failed softCheck is never read, the descriptions will be unused. String formatting for the descriptions should be performed in the callback, not ahead of time.

The context for a subject may hold a real "actual" value to test against, or it may have a placeholder within a call to describe. A context with a placeholder value will not invoke the callback to check expectations.

If both callbacks are invoked, the description callback will always be called strictly after the expectation callback is called.

Callbacks passed to a context should not throw.

void someExpectation() {
  context.expect(() => ['meets this expectation'], (actual) {
    if (_expectationIsMet(actual)) return null;
    return Rejection(which: ['does not meet this expectation']);
  });
}

Implementation

void expect(
    Iterable<String> Function() clause, Rejection? Function(T) predicate);