https://github.com/oberblastmeister/hspec-snap
Snapshot testing for hspec
https://github.com/oberblastmeister/hspec-snap
cli haskell hspec testing
Last synced: 2 months ago
JSON representation
Snapshot testing for hspec
- Host: GitHub
- URL: https://github.com/oberblastmeister/hspec-snap
- Owner: oberblastmeister
- License: bsd-3-clause
- Created: 2021-07-05T19:20:59.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-05T19:44:53.000Z (almost 4 years ago)
- Last Synced: 2025-01-16T19:25:52.484Z (4 months ago)
- Topics: cli, haskell, hspec, testing
- Language: Haskell
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# hspec-snap
**note**: this is still alpha quality software!
Snapshot tests assert values against a reference (the snapshot). This is useful when your reference values are very large or change often. Snapshot tests are also called golden tests or approval tests.
## Quick Start
You can write you hspec tests as normal but use `snap` instead of `it` when you want to use a snapshot test.
```haskell
import Test.Hspec
import Test.Hspec.Snapdescribe "a description"
snap "snapshot_test" $
show [1, 2, 3]it "should work" $
1 `shouldBe` 1
```After the test has been run for the first time, a snapshot file will be created. If the test changes, for example changing it to
```haskell
snap "snapshot_test" $
show [1, 2]
```the test will fail and a file called `snapshot_test.snap.new` will be created with the contents `[1, 2]`. You can then use the cli to decide what to do with the new file.
You can run
```sh
$ hsnap review
```
to get an interactive interface to accept, reject, or skip the new snapshot file.## CLI Options
```
Usage: hsnap COMMAND
a wrapper to run snapshot testsAvailable options:
-h,--help Show this help textAvailable commands:
test Run all the tests and then review
diff Show all the snapshot diffs
review Interactively review all snapshots
accept Accept all snapshots
reject Reject all snapshots
```## Inspiration
This library was inspired by [insta](https://github.com/mitsuhiko/insta) and
[hspec-golden](https://github.com/stackbuilders/hspec-golden)