https://github.com/rossmacarthur/goldie
🌟 Simple golden file testing for Rust
https://github.com/rossmacarthur/goldie
crate golden rust testing
Last synced: about 1 year ago
JSON representation
🌟 Simple golden file testing for Rust
- Host: GitHub
- URL: https://github.com/rossmacarthur/goldie
- Owner: rossmacarthur
- License: apache-2.0
- Created: 2021-10-02T20:40:53.000Z (over 4 years ago)
- Default Branch: trunk
- Last Pushed: 2024-04-21T15:34:02.000Z (about 2 years ago)
- Last Synced: 2025-04-13T16:09:08.787Z (about 1 year ago)
- Topics: crate, golden, rust, testing
- Language: Rust
- Homepage:
- Size: 53.7 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# goldie
[](https://crates.io/crates/goldie)
[](https://docs.rs/goldie)
[](https://github.com/rossmacarthur/goldie/actions/workflows/build.yaml)
Simple golden file testing for Rust.
```text
goldie::assert!(text);
```
## 🚀 Getting started
Add `goldie` to your project as a dev dependency.
```sh
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.
```rust,no_run
#[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](https://github.com/rossmacarthur/upon) e.g. `{{ value.field }}`.
You cannot use `GOLDIE_UPDATE=true` to automatically update templated golden
files.
```rust,no_run
#[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](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.