Code Monkey home page Code Monkey logo

goldie's Introduction

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.

goldie's People

Contributors

rossmacarthur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

goldie's Issues

Cargo test doesn't work with goldie

Step 1. Create a new empty directory. Run cargo init.
Step 2. Run cargo add --dev goldie
Step 3. Run cargo test

This will result in the following error:

error: cannot find derive macro `Deserialize` in this scope
   --> /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/goldie-0.4.2/src/lib.rs:294:22
    |
294 |             #[derive(Deserialize)]
    |                      ^^^^^^^^^^^
    |
note: `Deserialize` is imported here, but it is only a trait, without a derive macro
   --> /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/goldie-0.4.2/src/lib.rs:64:13
    |
64  | use serde::{Deserialize, Serialize};
    |             ^^^^^^^^^^^

error[E0277]: the trait bound `Manifest: Deserialize<'_>` is not satisfied
    --> /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/goldie-0.4.2/src/lib.rs:305:38
     |
305  |             let manifest: Manifest = serde_json::from_slice(&output.stdout).unwrap();
     |                                      ^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `Manifest`
     |
     = help: the following other types implement trait `Deserialize<'de>`:
               &'a Path
               &'a [u8]
               &'a str
               ()
               (T0, T1)
               (T0, T1, T2)
               (T0, T1, T2, T3)
               (T0, T1, T2, T3, T4)
             and 127 others
note: required by a bound in `from_slice`
    --> /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.91/src/de.rs:2561:8
     |
2561 |     T: de::Deserialize<'a>,
     |        ^^^^^^^^^^^^^^^^^^^ required by this bound in `from_slice`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `goldie` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Rust/cargo versions:

username@DESKTOP-AADV0LD:~/repos/goldie-test-repo$ cargo --version
cargo 1.65.0 (4bc8f24d3 2022-10-20)
username@DESKTOP-AADV0LD:~/repos/goldie-test-repo$ rustc --version
rustc 1.65.0 (897e37553 2022-11-02)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.