Watermelon - yet another Gherkin BDD testing tool

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.

6 Likes

Awesome! Looks like we will have a sleek successor to white_bread soon? :slight_smile:

2 Likes

I have released version 0.2.0-pre.0 of Watermelon that supports scenario outlines and data tables

There is discussion how data tables should be handled, so if anyone has any insights, then these will be welcome in the issue.

From now I find it as a mostly feature-complete solution that from now I will try to document better before 1.0.0.

5 Likes