damock

Crates.iodamock
lib.rsdamock
version
sourcesrc
created_at2024-10-15 20:39:19.630379
updated_at2024-10-20 08:18:37.669112
descriptionDerivable data mocking for tests
homepage
repositoryhttps://github.com/gibbz00/damock
max_upload_size
id1410327
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Gabriel Hansson (gibbz00)

documentation

README

Damock - Composable Data Mocking

ci_status codecov license crates_io docs_rs

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.

Commit count: 28

cargo fmt