kale v0.5.1 Kale.FeatureCase

An ExUnit test case for writing features using Kale.

Usage

defmodule MyTest do
  use Kale.FeatureCase, async: true

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

  defgiven "some precondition" do
    # ...
  end

  defwhen "action {action} happens" do
    # interpolated variables are magically available
    result = do_something(action)
    # if the step returns a map, it will be merged with the test context
    %{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.

Link to this section Summary

Functions

Generate a step definition matching a particular string and optionally a context map. See the module documentation for usage examples.

Generate a feature block, which corresponds to an ExUnit describe.

Generate a scenario block, which corresponds to an ExUnit test.

Link to this section Functions

Link to this macro

defgiven(step, context \\ {:%{}, [], []}, list) (macro)
defgiven(String.t(), Macro.t(), [{:do, Macro.t()}]) :: Macro.t()

Generate a step definition matching a particular string and optionally a context map. See the module documentation for usage examples.

The given, when and then steps are actually interchangeable – the separate macros are provided for readability only.

Link to this macro

defthen(step, context \\ {:%{}, [], []}, list) (macro)
defthen(String.t(), Macro.t(), [{:do, Macro.t()}]) :: Macro.t()

An alias for defgiven/2.

Link to this macro

defwhen(step, context \\ {:%{}, [], []}, list) (macro)
defwhen(String.t(), Macro.t(), [{:do, Macro.t()}]) :: Macro.t()

An alias for defgiven/2.

Link to this macro

feature(name, list) (macro)
feature(String.t(), [{:do, Macro.t()}]) :: Macro.t()

Generate a feature block, which corresponds to an ExUnit describe.

Link to this macro

scenario(name, body) (macro)
scenario(String.t(), String.t()) :: Macro.t()

Generate a scenario block, which corresponds to an ExUnit test.