| Crates.io | mockimbap |
| lib.rs | mockimbap |
| version | 0.1.0 |
| created_at | 2024-11-25 09:06:47.019774+00 |
| updated_at | 2024-11-25 09:06:47.019774+00 |
| description | Mockimbap is a macro for mocking Rust functions |
| homepage | |
| repository | https://github.com/neverprogrammer/mockimbap |
| max_upload_size | |
| id | 1460096 |
| size | 7,277 |
Add the following to your Cargo.toml:
[dependencies]
mockimbap = "0.1.0"
#[mockimbap::mockable]
trait Foo {
fn foo(&self) -> i32;
}
#[return_at(foo, 1)]
#[mock(Foo)]
struct MockFoo;
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;