@@ -294,6 +294,7 @@ pub type AfterHookFn<World> = for<'a> fn(
294294 & ' a gherkin:: Feature ,
295295 Option < & ' a gherkin:: Rule > ,
296296 & ' a gherkin:: Scenario ,
297+ & ' a event:: ScenarioFinished ,
297298 Option < & ' a mut World > ,
298299) -> LocalBoxFuture < ' a , ( ) > ;
299300
@@ -619,6 +620,7 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
619620 & ' a gherkin:: Feature ,
620621 Option < & ' a gherkin:: Rule > ,
621622 & ' a gherkin:: Scenario ,
623+ & ' a event:: ScenarioFinished ,
622624 Option < & ' a mut World > ,
623625 ) -> LocalBoxFuture < ' a , ( ) > ,
624626 {
@@ -706,6 +708,7 @@ where
706708 & ' a gherkin:: Feature ,
707709 Option < & ' a gherkin:: Rule > ,
708710 & ' a gherkin:: Scenario ,
711+ & ' a event:: ScenarioFinished ,
709712 Option < & ' a mut W > ,
710713 ) -> LocalBoxFuture < ' a , ( ) >
711714 + ' static ,
@@ -873,6 +876,7 @@ async fn execute<W, Before, After>(
873876 & ' a gherkin:: Feature ,
874877 Option < & ' a gherkin:: Rule > ,
875878 & ' a gherkin:: Scenario ,
879+ & ' a event:: ScenarioFinished ,
876880 Option < & ' a mut W > ,
877881 ) -> LocalBoxFuture < ' a , ( ) > ,
878882{
@@ -1046,6 +1050,7 @@ where
10461050 & ' a gherkin:: Feature ,
10471051 Option < & ' a gherkin:: Rule > ,
10481052 & ' a gherkin:: Scenario ,
1053+ & ' a event:: ScenarioFinished ,
10491054 Option < & ' a mut W > ,
10501055 ) -> LocalBoxFuture < ' a , ( ) > ,
10511056{
@@ -1176,13 +1181,22 @@ where
11761181 }
11771182 . await ;
11781183
1179- let world = match & mut result {
1180- Ok ( world) => world. take ( ) ,
1181- Err ( exec_err) => exec_err. take_world ( ) ,
1184+ let ( world, scenario_finished_ev) = match & mut result {
1185+ Ok ( world) => ( world. take ( ) , event:: ScenarioFinished :: StepPassed ) ,
1186+ Err ( exec_err) => (
1187+ exec_err. take_world ( ) ,
1188+ exec_err. get_scenario_finished_event ( ) ,
1189+ ) ,
11821190 } ;
11831191
11841192 let ( world, after_hook_meta, after_hook_error) = self
1185- . run_after_hook ( world, & feature, rule. as_ref ( ) , & scenario)
1193+ . run_after_hook (
1194+ world,
1195+ & feature,
1196+ rule. as_ref ( ) ,
1197+ & scenario,
1198+ scenario_finished_ev,
1199+ )
11861200 . await
11871201 . map_or_else (
11881202 |( w, meta, info) | ( w. map ( Arc :: new) , Some ( meta) , Some ( info) ) ,
@@ -1260,7 +1274,7 @@ where
12601274 retries : Option < Retries > ,
12611275 ) -> Result < Option < W > , ExecutionFailure < W > > {
12621276 let init_world = async {
1263- AssertUnwindSafe ( W :: new ( ) )
1277+ AssertUnwindSafe ( async { W :: new ( ) . await } )
12641278 . catch_unwind ( )
12651279 . await
12661280 . map_err ( Info :: from)
@@ -1284,12 +1298,15 @@ where
12841298 ) ) ;
12851299
12861300 let fut = init_world. and_then ( |mut world| async {
1287- let fut = ( hook) (
1288- feature. as_ref ( ) ,
1289- rule. as_ref ( ) . map ( AsRef :: as_ref) ,
1290- scenario. as_ref ( ) ,
1291- & mut world,
1292- ) ;
1301+ let fut = async {
1302+ ( hook) (
1303+ feature. as_ref ( ) ,
1304+ rule. as_ref ( ) . map ( AsRef :: as_ref) ,
1305+ scenario. as_ref ( ) ,
1306+ & mut world,
1307+ )
1308+ . await ;
1309+ } ;
12931310 match AssertUnwindSafe ( fut) . catch_unwind ( ) . await {
12941311 Ok ( ( ) ) => Ok ( world) ,
12951312 Err ( i) => Err ( ( Info :: from ( i) , Some ( world) ) ) ,
@@ -1361,7 +1378,10 @@ where
13611378 let mut world = if let Some ( w) = world {
13621379 w
13631380 } else {
1364- match AssertUnwindSafe ( W :: new ( ) ) . catch_unwind ( ) . await {
1381+ match AssertUnwindSafe ( async { W :: new ( ) . await } )
1382+ . catch_unwind ( )
1383+ . await
1384+ {
13651385 Ok ( Ok ( w) ) => w,
13661386 Ok ( Err ( e) ) => {
13671387 let e = event:: StepError :: Panic ( coerce_into_info (
@@ -1376,7 +1396,7 @@ where
13761396 }
13771397 } ;
13781398
1379- match AssertUnwindSafe ( step_fn ( & mut world, ctx) )
1399+ match AssertUnwindSafe ( async { step_fn ( & mut world, ctx) . await } )
13801400 . catch_unwind ( )
13811401 . await
13821402 {
@@ -1512,17 +1532,22 @@ where
15121532 feature : & Arc < gherkin:: Feature > ,
15131533 rule : Option < & Arc < gherkin:: Rule > > ,
15141534 scenario : & Arc < gherkin:: Scenario > ,
1535+ ev : event:: ScenarioFinished ,
15151536 ) -> Result <
15161537 ( Option < W > , Option < AfterHookEventsMeta > ) ,
15171538 ( Option < W > , AfterHookEventsMeta , Info ) ,
15181539 > {
15191540 if let Some ( hook) = self . after_hook . as_ref ( ) {
1520- let fut = ( hook) (
1521- feature. as_ref ( ) ,
1522- rule. as_ref ( ) . map ( AsRef :: as_ref) ,
1523- scenario. as_ref ( ) ,
1524- world. as_mut ( ) ,
1525- ) ;
1541+ let fut = async {
1542+ ( hook) (
1543+ feature. as_ref ( ) ,
1544+ rule. as_ref ( ) . map ( AsRef :: as_ref) ,
1545+ scenario. as_ref ( ) ,
1546+ & ev,
1547+ world. as_mut ( ) ,
1548+ )
1549+ . await ;
1550+ } ;
15261551
15271552 let started = event:: Metadata :: new ( ( ) ) ;
15281553 let res = AssertUnwindSafe ( fut) . catch_unwind ( ) . await ;
@@ -2201,6 +2226,23 @@ impl<W> ExecutionFailure<W> {
22012226 | Self :: StepPanicked { world, .. } => world. take ( ) ,
22022227 }
22032228 }
2229+
2230+ /// Creates an [`event::ScenarioFinished`] from this [`ExecutionFailure`].
2231+ fn get_scenario_finished_event ( & self ) -> event:: ScenarioFinished {
2232+ use event:: ScenarioFinished :: {
2233+ BeforeHookFailed , StepFailed , StepSkipped ,
2234+ } ;
2235+
2236+ match self {
2237+ Self :: BeforeHookPanicked { panic_info, .. } => {
2238+ BeforeHookFailed ( Arc :: clone ( panic_info) )
2239+ }
2240+ Self :: StepSkipped ( _) => StepSkipped ,
2241+ Self :: StepPanicked {
2242+ captures, loc, err, ..
2243+ } => StepFailed ( captures. clone ( ) , * loc, err. clone ( ) ) ,
2244+ }
2245+ }
22042246}
22052247
22062248#[ cfg( test) ]
0 commit comments