pub trait MockFn: Sized + 'static + for<'i> MockInputs<'i> {
    type Output: ?Sized;

    const NAME: &'static str;

    fn debug_inputs<'i>(inputs: &<Self as MockInputs<'i>>::Inputs) -> String;

    fn stub<E>(self, each_fn: E) -> Clause
    where
        E: FnOnce(&mut Each<Self>)
, { ... } fn each_call<M>(self, matching: M) -> Match<'static, Self, InAnyOrder>
    where
        M: for<'i> Fn(&<Self as MockInputs<'i>>::Inputs) -> bool + Send + Sync + 'static
, { ... } fn next_call<M>(self, matching: M) -> Match<'static, Self, InOrder>
    where
        M: for<'i> Fn(&<Self as MockInputs<'i>>::Inputs) -> bool + Send + Sync + 'static
, { ... } }
Expand description

The main trait used for unimock configuration.

MockFn describes functional APIs that may be called via dispatch, a.k.a. Inversion of Control. Virtuality should be regarded as as test-time virtuality: A virtual function is either the real deal (see Unmock) OR it is mocked.

In Rust, the most convenient way to perform a virtualized/dispatched function call is to call a trait method.

MockFn only provides metadata about an API, it is not directly callable.

As this is a trait itself, it needs to be implemented to be useful. Methods are not types, so we cannot implement MockFn for those. But a surrogate type can be introduced:

trait ILoveToMock {
    fn method(&self);
}

// The method can be referred to via the following empty surrogate struct:
struct ILoveToMock__method;

/* impl MockFn for Mockable_method ... */

Required Associated Types

The output of the function.

Required Associated Constants

The name to use for runtime errors.

Required Methods

Compute some debug representation of the inputs.

Provided Methods

Create a stubbing clause by grouping calls.

A stub sets up call patterns on a single function, that can be matched in any order.

For exact order verification, reach for MockFn::next_call instead.

Define a stub-like call pattern directly on the MockFn.

This is a shorthand to avoid calling MockFn::stub if there is only one call pattern that needs to be specified on this MockFn.

Initiate a call pattern builder intended to be used as a Clause with exact order verification. The build sequence should end with in_order.

This differens from MockFn::stub, in that that a stub defines all call patterns without any specific required call order. This function takes only single input matcher, that MUST be matched in the order specified, relative to other next calls.

Implementors