Macro to implement stub object for a trait.
Stub traits is a technique to simulate some comportments or to avoid to be blocked by a specific part of the code that is not implemented yet.
stub_trait is generally only used by tests. Add the following snippet into your Cargo.toml
:
toml
[dev-dependencies]
stub_trait = "1.0.0"
You can use it like this: ```rust
use stub_trait::stub;
trait Animal { fn feed(&self, quantity: usize) -> &str; }
fn test() { let animal = StubAnimal::new().withstuboffeed(|i, quantity| { if i == 0 { asserteq!(quantity, 10); "sad!" } else if i == 1 { asserteq!(quantity, 20); "happy!" } else { panic!("too much invocations!") } }); asserteq!(animal.feed(10), "sad!"); asserteq!(animal.feed(20), "happy!"); asserteq!(animal.countcallsof_feed(), 2); } ```
See CONTRIBUTING.md file.