Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mockiato/mockiato
A strict, yet friendly mocking library for Rust 2018
https://github.com/mockiato/mockiato
mock mocking rust
Last synced: 3 months ago
JSON representation
A strict, yet friendly mocking library for Rust 2018
- Host: GitHub
- URL: https://github.com/mockiato/mockiato
- Owner: mockiato
- License: mit
- Archived: true
- Created: 2018-08-24T16:12:26.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-31T08:53:53.000Z (6 months ago)
- Last Synced: 2024-07-05T16:24:51.390Z (4 months ago)
- Topics: mock, mocking, rust
- Language: Rust
- Homepage:
- Size: 1.02 MB
- Stars: 226
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license.txt
Awesome Lists containing this project
README
# Mockiato
> [!WARNING]
> Mockiato is no longer maintained and thus the repository has been archived.A strict, yet friendly mocking library for Rust 2018
## ⚠️ Disclaimer for working with stable rust
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.## [Docs](https://docs.rs/mockiato)
## Quickstart
```rust
#[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
Trait bounds are currently not supported meaning that the supertraits will not be implemented for mocks.
The following traits are always implemented for mocks:
- [Debug](https://doc.rust-lang.org/std/fmt/trait.Debug.html)
Example: [`cargo run --example debug`](./examples/debug.rs)
- [Clone](https://doc.rust-lang.org/std/clone/trait.Clone.html)
Example: [`cargo test --example clone`](./examples/clone.rs)
- [Default](https://doc.rust-lang.org/std/default/trait.Default.html)
Example: [`cargo test --example default`](./examples/default.rs)## Downcasting
An example of how to use downcasting with mockiato can be found in the [`downcasting`](./examples/downcasting.rs) example.
## Contributing
### Enable debug impls in codegen
```bash
cargo test --features mockiato-codegen/debug-impls
```