Crates.io | mockiato |
lib.rs | mockiato |
version | 0.9.6 |
source | src |
created_at | 2019-02-11 15:31:42.830748 |
updated_at | 2024-05-31 08:52:47.832212 |
description | A strict, yet friendly mocking library for Rust 2018 |
homepage | |
repository | https://github.com/mockiato/mockiato |
max_upload_size | |
id | 114102 |
size | 95,670 |
[!WARNING] Mockiato is no longer maintained and thus the repository has been archived.
A strict, yet friendly mocking library for Rust 2018
Mockiato relies on the unstable proc_macro_diagnostics
API to print helpful messages
and the unstable specialization
feature to be able to print expected calls.
Mocks work as expected on stable rust, but diagnostics are very limited.
We recommend re-running failing tests using nighly rust in order to pin-point the issue.
#[cfg(test)]
use mockiato::mockable;
#[cfg_attr(test, mockable)]
trait Greeter {
fn greet(&self, name: &str) -> String;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn greet_the_world() {
let mut greeter = GreeterMock::new();
greeter
.expect_greet(|arg| arg.partial_eq("world"))
.times(1..2)
.returns(String::from("Hello world"));
assert_eq!("Hello world", greeter.greet("world"));
}
}
Trait bounds are currently not supported meaning that the supertraits will not be implemented for mocks.
The following traits are always implemented for mocks:
cargo run --example debug
cargo test --example clone
cargo test --example default
An example of how to use downcasting with mockiato can be found in the downcasting
example.
cargo test --features mockiato-codegen/debug-impls