Giter Site home page Giter Site logo

watermelon's Introduction

Watermelon

Super simple Gherkin features to ExUnit tests translator.

Inspired by Cabbage, but with slightly different API and few ideas of my own to simplify working with the library.

Installation

The package can be installed by adding watermelon to your list of dependencies in mix.exs:

def deps do
  [
    {:watermelon, "~> 0.1.0", only: [:test]}
  ]
end

The docs can be found at https://hexdocs.pm/watermelon.

Usage

Define file tests/feature/coffe.feature:

Feature: Serve coffee
  Coffee should not be served until paid for
  Coffee should not be served until the button has been pressed
  If there is no coffee left then money should be refunded

  Scenario: Buy last coffee
    Given there are 1 coffees left in the machine
    And I have deposited £1
    When I press the coffee button
    Then I should be served a coffee
  Scenario Outline: Coffee count
    Given there are <start> coffees left in the machine
    And I have deposited £<money>
    When I press the coffee button <orders> times
    Then I should have <left> coffees

    Examples:
      | start | money | orders | left |
      |    12 |     5 |      5 |    7 |
      |    20 |     5 |      5 |   15 |

In your test module:

defmodule MyTest do
  use ExUnit.Case
  use Watermelon.Case

  feature_file("coffee.feature")

  defgiven match(number) when "there are {int} coffee(s) left in the machine" do
    {:ok, %{machine: Machine.put_coffee(Machine.new(), number)}}
  end

  defgiven match(number) when "I have deposited £{int}", context: %{machine: machine} do
    {:ok, %{machine: Machine.deposit(machine, nil, number)}}
  end

  defwhen match when "I press the coffee button", context: %{machine: machine} do
    assert {:ok, machine} = Machine.press_coffee(machine)
    {:ok, machine: machine}
  end

  defwhen match(n) when "I press the coffee button {int} times", context: %{machine: machine} do
    machine =
      for _ <- 1..n, reduce: machine do
        machine ->
          assert {:ok, machine} = Machine.press_coffee(machine)

          machine
      end

    {:ok, machine: machine}
  end

  defthen match when "I should be served a coffee", context: state do
    assert {:coffee, _} = Machine.take_drink(state.machine)

    :ok
  end

  defthen match(num) when "I should have {int} coffee(s)", context: %{machine: machine} do
    assert machine.coffees == num

    :ok
  end
end

LICENSE

Mozilla Public License 2.0, see LICENSE.

watermelon's People

Contributors

hauleth avatar matthew-myers-boseprofessional avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

watermelon's Issues

Sponsoring improvements to the library

Hi @hauleth

Do you offer open-source dev services? We are using watermelon in our backend and there are some improvements we'd like to make. Most of them are related to better error messages.

If you're interested, we can create some GH issues for you to take a look at. And I noticed you're setup with GitHub sponsors, so we could pay you directly through there.

Please let me know here or at [email protected]. Whatever is more convenient for you :)

Cheers,
Venkat

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.