1 unstable release
0.1.0 | Nov 25, 2024 |
---|
#475 in Procedural macros
155 downloads per month
8KB
91 lines
Usage
Add the following to your Cargo.toml
:
[dependencies]
mockimbap = "0.1.0"
Example
#[mockimbap::mockable]
trait Foo {
fn foo(&self) -> i32;
}
#[return_at(foo, 1)]
#[mock(Foo)]
struct MockFoo;
❗️ Limitation
Currently, the macro only supports mocking functions that return a value. The macro does not support mocking functions that take arguments.
And Always must mock after mockimbap::mockable
So, you may do like this:
// mock.rs
#[mock(Foo)]
struct MockFoo;
// main.rs
#[mockimbap::mockable]
trait Foo {
fn foo(&self) -> i32;
}
fn main() {
let mock = MockFoo;
assert_eq!(mock.foo(), 1);
}
// Like this, you must put mock file after mockimbap::mockable
mod mock;
Dependencies
~225–670KB
~16K SLoC