| Crates.io | goldie |
| lib.rs | goldie |
| version | 0.5.0 |
| created_at | 2021-10-02 20:39:34.552147+00 |
| updated_at | 2024-04-21 15:35:10.301434+00 |
| description | Simple golden file testing |
| homepage | |
| repository | https://github.com/rossmacarthur/goldie |
| max_upload_size | |
| id | 459538 |
| size | 28,533 |
Simple golden file testing for Rust.
goldie::assert!(text);
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)
}
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.