mockimbap

Crates.iomockimbap
lib.rsmockimbap
version0.1.0
created_at2024-11-25 09:06:47.019774+00
updated_at2024-11-25 09:06:47.019774+00
descriptionMockimbap is a macro for mocking Rust functions
homepage
repositoryhttps://github.com/neverprogrammer/mockimbap
max_upload_size
id1460096
size7,277
LCW (wHoIsDReAmer)

documentation

README

🍙 Mockimbap

Mockimbap is a macro for mocking Rust functions

Crates.io Rust Version

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;
Commit count: 0

cargo fmt