Skip to content

Commit 2aa4cdc

Browse files
committed
cucumber-rs#366 Add documentation warning about calling .after multiple times
1 parent 69017ed commit 2aa4cdc

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

book/src/writing/hooks.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ World::cucumber()
3838
> __WARNING__: __Think twice before using [`Before` hook]!__
3939
> 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.
4040
41-
41+
> __WARNING__: __Only one [`Before` hook] can be registered!__
42+
> Only one [`Before` hook] can be be registered, if multiple `.before` calls are made only the last one will be run.
4243
4344

4445
## `After` hook
@@ -72,7 +73,8 @@ World::cucumber()
7273
7374
> __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.
7475
75-
76+
> __WARNING__: __Only one [`After` hook] can be registered!__
77+
> Only one [`After` hook] can be be registered, if multiple `.after` calls are made only the last one will be run.
7678
7779

7880
[`After` hook]: https://cucumber.io/docs/cucumber/api#after

src/cucumber.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,9 @@ where
10151015
/// Sets a hook, executed on each [`Scenario`] before running all its
10161016
/// [`Step`]s, including [`Background`] ones.
10171017
///
1018+
/// Note: Only one [`Before` hook] can be be registered, if multiple
1019+
/// `.before` calls are made only the last one will be run.
1020+
///
10181021
/// [`Background`]: gherkin::Background
10191022
/// [`Scenario`]: gherkin::Scenario
10201023
/// [`Step`]: gherkin::Step
@@ -1046,6 +1049,9 @@ where
10461049
/// Sets a hook, executed on each [`Scenario`] after running all its
10471050
/// [`Step`]s, even after [`Skipped`] of [`Failed`] [`Step`]s.
10481051
///
1052+
/// Note: Only one [`After` hook] can be be registered, if multiple
1053+
/// `.after` calls are made only the last one will be run.
1054+
///
10491055
/// Last `World` argument is supplied to the function, in case it was
10501056
/// initialized before by running [`before`] hook or any [`Step`].
10511057
///

src/runner/basic.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
577577
/// Sets a hook, executed on each [`Scenario`] before running all its
578578
/// [`Step`]s, including [`Background`] ones.
579579
///
580+
/// Note: Only one [`Before` hook] can be be registered, if multiple
581+
/// `.before` calls are made only the last one will be run.
582+
///
580583
/// [`Background`]: gherkin::Background
581584
/// [`Scenario`]: gherkin::Scenario
582585
/// [`Step`]: gherkin::Step
@@ -623,6 +626,9 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
623626
/// Sets hook, executed on each [`Scenario`] after running all its
624627
/// [`Step`]s, even after [`Skipped`] of [`Failed`] ones.
625628
///
629+
/// Note: Only one [`After` hook] can be be registered, if multiple
630+
/// `.after` calls are made only the last one will be run.
631+
///
626632
/// Last `World` argument is supplied to the function, in case it was
627633
/// initialized before by running [`before`] hook or any [`Step`].
628634
///

0 commit comments

Comments
 (0)