Crates.io | damock |
lib.rs | damock |
version | 0.1.3 |
created_at | 2024-10-15 20:39:19.630379+00 |
updated_at | 2024-10-20 08:18:37.669112+00 |
description | Derivable data mocking for tests |
homepage | |
repository | https://github.com/gibbz00/damock |
max_upload_size | |
id | 1410327 |
size | 8,187 |
use damock::Mock;
#[derive(Mock)]
struct Foo {
bar: Bar,
#[mock_default]
baz: u8
}
#[derive(Mock)]
enum Bar {
#[mock]
A,
B,
}
The former derive expands into:
// Derived mock implementations will
// always be conditionally compiled.
#[cfg(test)]
impl Mock for Foo {
fn mock() -> Self {
Self {
bar: Mock::mock(),
baz: Default::default(),
}
}
}
Toy application:
#[test]
fn computes_data() {
let actual = compute(DataInput::mock());
assert_eq!(DataOutput::mock(), actual);
}
The test
compiler configuration may be overridden to something else like so:
#[derive(damock::Mock)]
#[mock(feature = "mocks")]
struct Foo;
This may come in use when Mock
implementations need be shared between workspace crates.