Cucumberex.DSL (cucumberex v0.2.1)

Copy Markdown View Source

Step definition DSL.

Usage

defmodule MySteps do
  use Cucumberex.DSL

  given_ "I have {int} cukes in my belly", fn world, count ->
    Map.put(world, :cukes, count)
  end

  when_ ~r/I eat (\d+) cukes/, fn world, count_str ->
    count = String.to_integer(count_str)
    Map.update(world, :cukes, 0, &(&1 - count))
  end

  then_ "I should have {int} cukes", fn world, expected ->
    if world.cukes != expected do
      raise "Expected #{expected} cukes, got #{world.cukes}"
    end
    world
  end
end

Step functions: fn world, arg1, arg2, ... -> new_world end Call pending() inside to mark a step pending.

Summary

Functions

execute_step(fun, world, args)

Execute step: fun is {module, fun_name} or an anonymous fn.

given_(pattern, fun_ast)

(macro)

load_module(module, registry \\ Cucumberex.StepDefinition.Registry)

Load a step module into the registry.

parameter_type(name, regexp, transformer)

(macro)

pending()

(macro)

step(pattern, fun_ast)

(macro)

then_(pattern, fun_ast)

(macro)

when_(pattern, fun_ast)

(macro)

world_module(mod)

(macro)