Cucumber.Hooks (Cucumber v0.4.1)
View SourceProvides hooks for setup and teardown in Cucumber tests.
Hooks can be defined globally or filtered by tags. They are executed in the order they are defined, with Before hooks running in definition order and After hooks running in reverse order.
Examples
defmodule DatabaseSupport do
use Cucumber.Hooks
# Global before hook - runs for all scenarios
before_scenario context do
# Setup code
{:ok, Map.put(context, :setup, true)}
end
# Tagged before hook - only runs for @database scenarios
before_scenario "@database", context do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(MyApp.Repo)
if context.async do
Ecto.Adapters.SQL.Sandbox.mode(MyApp.Repo, {:shared, self()})
end
{:ok, context}
end
# After hooks run in reverse order
after_scenario _context do
# Cleanup code
:ok
end
end
Summary
Functions
Defines an after_scenario hook that runs after each scenario.
Defines a before_scenario hook that runs before each scenario.
Functions
Defines an after_scenario hook that runs after each scenario.
Can optionally be filtered by tag. After hooks run in reverse order of definition. The hook receives the test context.
Defines a before_scenario hook that runs before each scenario.
Can optionally be filtered by tag. The hook receives the test context and must return one of:
{:ok, context}
:ok
(keeps context unchanged)- map (merged into context)