snapshot-testing 0.1.1

Assert that a multi-line string equals the contents of an easily updatable snapshot file. Print a nice colored diff if not.
Documentation

Usage

Write a test:

#[test]
fn check_snapshot() {
    let value = "... contents to regression test ...";
    snapshot_testing::assert_eq_or_update(value, "snapshot.txt");
}

Update the snapshot file before the first test:

UPDATE_SNAPSHOTS=yes cargo test

Assert that current contents matches the contents of the snapshot file:

cargo test

Diffing Engine

We use the same excellent diffing engine that insta is using. But since we allow custom snapshot file extensions we do not suffer from Consider ways to avoid conflicts with Jest snapshots for external tools (like GitHub Linguist). That bug makes GitHub diffs horrible. Unfortunately the .gitattributes workaround does not work.

Audit the Code

This crate is ~30 lines of code. Audit with the following one-liner, but make sure you follow to the crates.io Data Access Policy:

curl -H "User-Agent: $USER at $HOST" \
     -L https://crates.io/api/v1/crates/snapshot-testing/0.1.1/download |
         tar --extract --gzip --to-stdout | less