BDD-like syntax for ExUnit
Clone or download
Latest commit 01f8391 Jun 6, 2018
Failed to load latest commit information.
config Initial commit. Jul 26, 2014
lib Add mix format Jun 6, 2018
test Add mix format Jun 6, 2018
.formatter.exs Add mix format Jun 6, 2018
.gitignore Update dev dependencies. Apr 21, 2015
.travis.yml Add mix format Jun 6, 2018 Bump version Jan 7, 2017
LICENSE Add LICENSE file Aug 5, 2015 Remove describe for elixir 1.3 support Jul 3, 2016
mix.exs Update dependencies Jun 6, 2018
mix.lock Update dependencies Jun 6, 2018


Build Status Hex Version Hex docs

ExSpec is a simple wrapper around ExUnit that adds Rspec-style macros. Specifically, it adds context and it.

While it takes inspiration from Rspec, ExSpec is significantly simplier. The context macro has only two functions:

  1. Aid test organization
  2. Prepend to the message of any it defined within its do blocks

The it macro is identical to ExUnit.Case.test except that it is aware of the messages of its surrounding context blocks. It also works seemlessly with ExUnit's describe function.

Other than the functionality described above, ExSpec is just ExUnit. When useing ExSpec, any options provided will be passed to ExUnit.Case (e.g. async: true).

A simple example is shown below. For more examples, see the tests.


defmodule PersonTest do
  use ExSpec, async: true

  describe "name" do
    context "with first and last name" do
      it "joins the names with a space" do
        drew = %Person{first_name: "Drew", last_name: "Olson"}

        assert == "Drew Olson"

    context "with only a first name" do
      it "returns the first name" do
        drew = %Person{first_name: "Drew", last_name: nil}

        assert == "Drew"


Add ex_spec to your mix.exs dependencies:

def deps do
  [{:ex_spec, "~> 2.0", only: :test}]