4 releases (breaking)

0.4.0 Jul 16, 2022
0.3.0 Jun 16, 2022
0.2.0 Mar 5, 2022
0.1.0 Oct 2, 2021

#125 in Testing

Download history 46/week @ 2022-06-05 38/week @ 2022-06-12 33/week @ 2022-06-19 12/week @ 2022-06-26 27/week @ 2022-07-03 52/week @ 2022-07-10 46/week @ 2022-07-17 52/week @ 2022-07-24 41/week @ 2022-07-31 62/week @ 2022-08-07 25/week @ 2022-08-14 31/week @ 2022-08-21 40/week @ 2022-08-28 69/week @ 2022-09-04 44/week @ 2022-09-11 104/week @ 2022-09-18

266 downloads per month
Used in 3 crates

MIT/Apache

13KB
284 lines

goldie

Crates.io Version Docs.rs Latest Build Status

Simple golden file testing for Rust.

goldie::assert!(text);

🚀 Getting started

Add goldie to your project as a dev dependency.

cargo add goldie --dev

In your test function assert the contents using goldie::assert!. The golden filename will be automatically determined based on the test file and test function name. Run tests with GOLDIE_UPDATE=true to automatically update golden files.

#[test]
fn example() {
    let text = { /* ... run the test ... */ }

    // assert that the contents of ./testdata/example.golden
    // are equal to `text`
    goldie::assert!(text)
}

Templated golden files are also supported using goldie::assert_template!. Something implementing serde::Serialize needs to be provided as context in order to render the template. Values are rendered using upon e.g. {{ value.field }}. You cannot use GOLDIE_UPDATE=true to automatically update templated golden files.

#[test]
fn example() {
    let text = { /* ... run the test ... */ }

    // assert that the contents of ./testdata/example.golden
    // are equal to `text` after rendering with `ctx`.
    let ctx = upon::value!{ value: "Hello World!" };
    goldie::assert_template!(&ctx, text)
}

License

Licensed under either of

at your option.

Dependencies

~1–1.5MB
~29K SLoC