From 2aa4cdceea110cdab98bbdfe2b4988b00a9648c9 Mon Sep 17 00:00:00 2001 From: Jonathan Parris Date: Thu, 17 Apr 2025 17:10:41 -0600 Subject: [PATCH] #366 Add documentation warning about calling .after multiple times --- book/src/writing/hooks.md | 6 ++++-- src/cucumber.rs | 6 ++++++ src/runner/basic.rs | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/book/src/writing/hooks.md b/book/src/writing/hooks.md index c936ae17..3b85c2f8 100644 --- a/book/src/writing/hooks.md +++ b/book/src/writing/hooks.md @@ -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 @@ -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 diff --git a/src/cucumber.rs b/src/cucumber.rs index c23eadcb..c301f8c2 100644 --- a/src/cucumber.rs +++ b/src/cucumber.rs @@ -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 @@ -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`]. /// diff --git a/src/runner/basic.rs b/src/runner/basic.rs index 60dec15f..2368d1be 100644 --- a/src/runner/basic.rs +++ b/src/runner/basic.rs @@ -577,6 +577,9 @@ impl Basic { /// 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 @@ -623,6 +626,9 @@ impl Basic { /// 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`]. ///