Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Mar 5, 2019
1 parent 9122f37 commit b0f9fed
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ This crate exports multiple macros for snapshot testing:

- `assert_snapshot_matches!` for comparing basic string snapshots.
- `assert_debug_snapshot_matches!` for comparing `Debug` outputs of values.
- `assert_display_snapshot_matches!` for comparing `Display` outputs of values.
- `assert_yaml_snapshot_matches!` for comparing YAML serialized
output of types implementing `serde::Serialize`.
- `assert_ron_snapshot_matches!` for comparing RON serialized output of
Expand All @@ -21,7 +20,8 @@ This crate exports multiple macros for snapshot testing:

Snapshots are stored in the `snapshots` folder right next to the test file
where this is used. The name of the file is `<module>__<name>.snap` where
the `name` of the snapshot has to be provided to the assertion macro.
the `name` of the snapshot has to be provided to the assertion macro. If
no name is provided the name is derived from the test name.

Additionally snapshots can also be stored inline. In that case the
`cargo-insta` tool is necessary. See [inline snapshots](#inline-snapshots)
Expand Down Expand Up @@ -62,6 +62,9 @@ fn test_snapshots() {
}
```

(If you do not want to provide a name for the snapshot read about
[unnamed snapshots](#unnamed-snapshots).)

The recommended flow is to run the tests once, have them fail and check
if the result is okay. By default the new snapshots are stored next
to the old ones with the extra `.new` extension. Once you are satisifed
Expand Down Expand Up @@ -188,6 +191,29 @@ assert_yaml_snapshot_matches!("user", &User {
});
```

## Unnamed Snapshots

All snapshot assertion functions let you leave out the snapshot name. In
that case the snapshot name is derived from the test name. This works
because the rust test runner names the thread by the test name and the
name is taken from the thread name. In case your test spawns additional
threads this will not work and you will need to provide a name explicitly.

Additionally if you have multiple snapshot assertions per test name a
counter will be appended:

```rust
#[test]
fn test_something() {
assert_snapshot_matches!("first value");
assert_snapshot_matches!("second value");
}
```

This will create two snapshots: `something` for the first value and
`something-2` for the second value. The leading `test_` prefix is removed
if the function starts with that name.

## Inline Snapshots

Additionally snapshots can also be stored inline. In that case the format
Expand Down

0 comments on commit b0f9fed

Please sign in to comment.