pub trait Clause: ClauseSealed { }
Expand description
A clause represents a recipe for creating a unimock instance.
Clauses may be terminal (basic) and non-terminal (composite). Terminal clauses are created with unimock’s builder API, non-terminals/composites are created by grouping other clauses in tuples.
use unimock::*;
#[unimock(api=FooMock)]
trait Foo {
fn foo(&self, i: i32) -> i32;
}
#[unimock(api=BarMock)]
trait Bar {
fn bar(&self, i: i32) -> i32;
}
#[unimock(api=BazMock)]
trait Baz {
fn baz(&self, i: i32) -> i32;
}
// A reusable function returning a composite clause from two terminals, by tupling them:
fn setup_foo_and_bar() -> impl Clause {
(
FooMock::foo.some_call(matching!(_)).returns(1),
BarMock::bar.some_call(matching!(_)).returns(2),
)
}
// Basic and composite clauses may be recombined again to make new tuples:
let mocked = Unimock::new((
setup_foo_and_bar(),
BazMock::baz.some_call(matching!(_)).returns(3),
));
assert_eq!(6, mocked.foo(0) + mocked.bar(0) + mocked.baz(0));