assert-rs / predicates-rs

Boolean-valued predicate functions in Rust
docs.rs/predicates
Apache License 2.0
166 stars 29 forks source link

Snapshot tests #69

Open killercup opened 5 years ago

killercup commented 5 years ago

Did we ever talk about snapshot tests? I don't recall, and I didn't find an issue in this or the assert_{cmd,cli} repos.

The idea is this: Instead of manually writing predicate::path::eq_file(Path::new("some.file")).utf8().unwrap();, you'd have a predicate::eq_snapshot!() macro that expands to a uniq filename predicate with the ability to create that file with the content it gets on the first test run or when using RECORD_SNAPSHOTS=1 or something similar.

epage commented 5 years ago

Good idea. While "golden state" tests are brittle, they can be useful and making it easier to update them would be a big help.

We'll also want to look into this for #33. The main impact of #33 on this issue is ensuring we have good names for both of them.

I'm assuming the snapshots would be kept under revision control.

Options for where to store

Next, what is the snapshot's filename

eq_snapshot would probably want a .utf8() like eq_file so we know when can provide more useful failure messages.

Any other API considerations?

epage commented 5 years ago

See insta for ideas we could pillage https://crates.io/crates/insta