Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DCzajkowski/snapshy
Browse files Browse the repository at this point in the history
  • Loading branch information
DCzajkowski committed May 9, 2019
2 parents 5af7fcc + 7b16e63 commit 3e0a04f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
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
53 changes: 47 additions & 6 deletions README.md
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.

0 comments on commit 3e0a04f

Please sign in to comment.