Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions book/src/writing/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ World::cucumber()
> __WARNING__: __Think twice before using [`Before` hook]!__
> Whatever happens in a [`Before` hook] is invisible to people reading `.feature`s. You should consider using a [`Background`] keyword as a more explicit alternative, especially if the setup should be readable by non-technical people. Only use a [`Before` hook] for low-level logic such as starting a browser or deleting data from a database.


> __WARNING__: __Only one [`Before` hook] can be registered!__
> Only one [`Before` hook] can be be registered, if multiple `.before` calls are made only the last one will be run.


## `After` hook
Expand Down Expand Up @@ -72,7 +73,8 @@ World::cucumber()

> __TIP__: [`After` hook] receives an [`event::ScenarioFinished`] as one of its arguments, which indicates why the [scenario] has finished (passed, failed or skipped). This information, for example, may be used to decide whether some external resources (like files) should be cleaned up if the [scenario] passes, or leaved "as is" if it fails, so helping to "freeze" the failure conditions for better investigation.


> __WARNING__: __Only one [`After` hook] can be registered!__
> Only one [`After` hook] can be be registered, if multiple `.after` calls are made only the last one will be run.


[`After` hook]: https://cucumber.io/docs/cucumber/api#after
Expand Down
6 changes: 6 additions & 0 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,9 @@ where
/// Sets a hook, executed on each [`Scenario`] before running all its
/// [`Step`]s, including [`Background`] ones.
///
/// Note: Only one [`Before` hook] can be be registered, if multiple
/// `.before` calls are made only the last one will be run.
///
/// [`Background`]: gherkin::Background
/// [`Scenario`]: gherkin::Scenario
/// [`Step`]: gherkin::Step
Expand Down Expand Up @@ -1046,6 +1049,9 @@ where
/// Sets a hook, executed on each [`Scenario`] after running all its
/// [`Step`]s, even after [`Skipped`] of [`Failed`] [`Step`]s.
///
/// Note: Only one [`After` hook] can be be registered, if multiple
/// `.after` calls are made only the last one will be run.
///
/// Last `World` argument is supplied to the function, in case it was
/// initialized before by running [`before`] hook or any [`Step`].
///
Expand Down
6 changes: 6 additions & 0 deletions src/runner/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
/// Sets a hook, executed on each [`Scenario`] before running all its
/// [`Step`]s, including [`Background`] ones.
///
/// Note: Only one [`Before` hook] can be be registered, if multiple
/// `.before` calls are made only the last one will be run.
///
/// [`Background`]: gherkin::Background
/// [`Scenario`]: gherkin::Scenario
/// [`Step`]: gherkin::Step
Expand Down Expand Up @@ -623,6 +626,9 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
/// Sets hook, executed on each [`Scenario`] after running all its
/// [`Step`]s, even after [`Skipped`] of [`Failed`] ones.
///
/// Note: Only one [`After` hook] can be be registered, if multiple
/// `.after` calls are made only the last one will be run.
///
/// Last `World` argument is supplied to the function, in case it was
/// initialized before by running [`before`] hook or any [`Step`].
///
Expand Down