-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:DCzajkowski/snapshy
- Loading branch information
Showing
2 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: elixir | ||
|
||
sudo: false | ||
|
||
matrix: | ||
include: | ||
- otp_release: 21.0 | ||
elixir: 1.8.1 | ||
|
||
script: | ||
- mix format --check-formatted | ||
- mix test --trace | ||
|
||
cache: | ||
directories: | ||
- priv/plts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,62 @@ | ||
# Snapshy | ||
|
||
**TODO: Add description** | ||
Snapshy is an Elixir package for running snapshot tests in ExUnit. More extensive documentation is coming soon. | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
by adding `snapshy` to your list of dependencies in `mix.exs`: | ||
Add `snapshy` to your list of dependencies in `mix.exs` and run `mix deps.get`: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
# ... | ||
{:snapshy, "~> 0.1.0"} | ||
] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at [https://hexdocs.pm/snapshy](https://hexdocs.pm/snapshy). | ||
## Overview | ||
|
||
The way this works: | ||
|
||
1. Add Snapshy to the test | ||
|
||
```diff | ||
defmodule TokenizerTest do | ||
+ use Snapshy | ||
use ExUnit.Case | ||
|
||
# ... | ||
end | ||
``` | ||
|
||
2. Replace `test` with `test_snapshot` | ||
|
||
```diff | ||
- test "correctly tokenizes booleans" do | ||
+ test_snapshot "correctly tokenizes booleans" do | ||
# ... | ||
end | ||
``` | ||
|
||
3. Replace an assertion with simple function call | ||
|
||
```diff | ||
- assert( | ||
- tokens("true false") == [ | ||
- boolean: "true", | ||
- boolean: "false" | ||
- ] | ||
- ) | ||
+ tokens("true false") | ||
``` | ||
|
||
The first time a snapshot will be created in `test/__snapshots__/path/to/test_file/function_name.stub`. The second time, an assertion will be made against the snapshot. If you make changes and you want to update snapshots, run `SNAPSHY_OVERRIDE=true mix test` instead of `mix test`. Verify in git every change is correct. | ||
|
||
Alternatively, you can use a macro call instead of the `test_snapshot` macro like so: | ||
```elixir | ||
test "correctly tokenizes booleans" do | ||
match_snapshot tokens("true false") | ||
end | ||
``` | ||
**Careful!** There can only be one `match_snapshot` call per test macro call. |