Watermelon is the small library for BDD that uses Gherkin syntax. This library is heavily inspired by the Cabbage, but takes slightly different approach for defining steps and modularity of the implementation. Additionally it implements Cucmber expressions right now (Cabbage is working on supporting that).
Usage is quite simple:
defmodule MyTest do
use ExUnit.Case, async: true
use Watermelon.Case
# Here we use inline feature description, but you can use `feature_file/1`
# which will import file from `test/features` directory (can be changed
# via configuration)
feature """
Feature: Example
Scenario: simple test
Given empty stack
And pushed 1
And pushed 2
When execute sum function
Then have 3 on top of stack
"""
defgiven match when "empty stack", do: {:ok, stack: []}
defgiven match(val) when "pushed {num}", context: %{stack: stack} do
{:ok, stack: [val | stack]}
end
defwhen match when "execute sum function", context: ctx do
assert [a, b | rest] = ctx.stack
{:ok, stack: [a + b | rest]}
end
defthen match(result) when "have {num} on top of stack", context: ctx do
assert [^result | _] = ctx.stack
end
end
Which will be rough equivalent of:
defmodule MyApp.FeatureTest do
use ExUnit.Case, async: true
test "simple test" do
stack = [1, 2]
assert [a, b | _] = stack
assert 3 == a + b
end
end
Documentation can be found on HexDocs, it is not perfect yet, but I hope to improve it in near future.