diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cedd9d7 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index b4306c8..3e1ad43 100644 --- a/README.md +++ b/README.md @@ -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.