mockimbap 0.1.0

Mockimbap is a macro for mocking Rust functions
Documentation
  • Coverage
  • 50%
    2 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 7.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 289.34 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wHoIsDReAmer

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;