View Source Kale (kale v0.8.1)

An ExUnit test case for writing features using Kale.

Usage

defmodule MyTest do
  use ExUnit.Case, async: true
  use Kale

  feature "Feature description here" do
    scenario "Scenario description here", """
    Given some precondition
    When action {foo} happens
    Then the result is {bar}
    """
  end

  defgiven "some precondition" do
    # ...
  end

  defwhen "action {action} happens" do
    # interpolated variables are magically available
    result = do_something(action)
    # if the step returns a {:reply, _} tuple containing a map or keyword
    # list, it will be merged with the test context
    {:reply, result: result}
  end

  defthen "the result is {expected}", %{result: result} do
    # Optional second argument for context, as per standard ExUnit
    assert result == expected
  end
end

Each feature generates a describe, and each scenario a test. Standard ExUnit features such as setup can be used as normal.

To avoid the formatter inserting extra parens, you can specify import_deps: [:kale] in your .formatter.exs.