mtrudel / machete

Literate test matchers for ExUnit
MIT License
56 stars 1 forks source link
elixir elixir-lang exunit exunit-assertions rspec-matchers testing

Machete

Build Status Docs Hex.pm

Machete provides ergonomic match operators to help make your ExUnit tests more literate

The easiest way to explain Machete is to show it in action:

defmodule ExampleTest do
  use ExUnit.Case
  use Machete

  test "example test" do
    response = %{
      id: 1,
      name: "Moe Fonebone",
      is_admin: false,
      created_at: DateTime.utc_now()
    }

    assert response ~> %{
      id: integer(positive: true),
      name: string(),
      is_admin: false,
      created_at: datetime(roughly: :now, time_zone: :utc)
    }
  end
end

At its heart, Machete provides the following two things:

These building blocks let you define test expectations that can match data against any combination of literals, variables, or parametrically defined matchers

When your matches fail, Machete provides useful error messages in ExUnit that point you directly at any failing matches using jq syntax

Installation

Machete is available in Hex, and can be installed by adding machete to your list of dependencies in mix.exs:

def deps do
  [
    {:machete, "~> 0.2.8"}
  ]
end

Documentation is published on HexDocs

License

MIT