Crate stub_trait
source ·Expand description
Macro to implement stub object for a trait.
Usage
use stub_trait::stub;
#[stub]
trait Animal {
fn feed(&self, quantity: usize) -> &str;
}
let animal = StubAnimal::new().with_stub_of_feed(|i, quantity| {
if i == 0 {
assert_eq!(quantity, 10);
"sad!"
} else if i == 1 {
assert_eq!(quantity, 20);
"happy!"
} else {
panic!("too much invocations!")
}
});
assert_eq!(animal.feed(10), "sad!");
assert_eq!(animal.feed(20), "happy!");
assert_eq!(animal.count_calls_of_feed(), 2);