Cucumberex.Hook (cucumberex v0.2.1)

Copy Markdown View Source

A registered hook with phase, tag filter, and implementation.

Summary

Functions

Check if a hook should apply to a scenario tagged with the given tags. A hook with no tag expression applies to all scenarios.

Build a Hook. A fresh UUID is assigned to :id on each call.

Types

phase()

@type phase() ::
  :before
  | :after
  | :around
  | :before_step
  | :after_step
  | :before_all
  | :after_all
  | :install_plugin

t()

@type t() :: %Cucumberex.Hook{
  fun: function(),
  id: String.t(),
  location: String.t(),
  order: integer(),
  phase: phase(),
  tag_expression: String.t() | nil
}

Functions

applies_to?(hook, tags)

Check if a hook should apply to a scenario tagged with the given tags. A hook with no tag expression applies to all scenarios.

Examples

iex> h = %Cucumberex.Hook{tag_expression: nil}
iex> Cucumberex.Hook.applies_to?(h, ["@any"])
true

iex> h = %Cucumberex.Hook{tag_expression: "@smoke"}
iex> Cucumberex.Hook.applies_to?(h, ["@smoke"])
true

iex> h = %Cucumberex.Hook{tag_expression: "@smoke"}
iex> Cucumberex.Hook.applies_to?(h, ["@other"])
false

new(phase, fun, opts \\ [])

Build a Hook. A fresh UUID is assigned to :id on each call.

Examples

iex> h = Cucumberex.Hook.new(:before, fn _ -> :ok end, tags: "@smoke")
iex> {h.phase, h.tag_expression, h.order, h.location}
{:before, "@smoke", 0, "unknown"}

iex> h = Cucumberex.Hook.new(:after, fn _ -> :ok end)
iex> h.tag_expression
nil