8 releases (4 breaking)

0.5.0 Apr 21, 2024
0.4.3 Jan 8, 2023
0.4.2 Nov 15, 2022
0.4.1 Oct 3, 2022
0.1.0 Oct 2, 2021

#146 in Testing

Download history 335/week @ 2024-10-26 312/week @ 2024-11-02 773/week @ 2024-11-09 824/week @ 2024-11-16 313/week @ 2024-11-23 131/week @ 2024-11-30 146/week @ 2024-12-07 139/week @ 2024-12-14 54/week @ 2024-12-21 41/week @ 2024-12-28 162/week @ 2025-01-04 182/week @ 2025-01-11 212/week @ 2025-01-18 671/week @ 2025-01-25 1290/week @ 2025-02-01 1056/week @ 2025-02-08

3,306 downloads per month
Used in 15 crates

MIT/Apache

15KB
285 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

This project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies

~1.3–2.2MB
~45K SLoC