@@ -2,7 +2,7 @@ package io.cucumber.scala
22
33import java .lang .reflect .{ParameterizedType , Type }
44
5- import io .cucumber .scala .Aliases .{ DefaultDataTableCellTransformerBody , DefaultDataTableEntryTransformerBody , DefaultParameterTransformerBody , DocStringDefinitionBody , HookBody }
5+ import io .cucumber .scala .Aliases ._
66
77import scala .reflect .ClassTag
88
@@ -28,70 +28,72 @@ trait ScalaDsl extends BaseScalaDsl with StepDsl with HookDsl with DataTableType
2828
2929private [scala] trait HookDsl extends BaseScalaDsl {
3030
31- // TODO support Before/After with no parameter
31+ private sealed trait HookType
3232
33- def Before (body : HookBody ): Unit = {
34- Before (EMPTY_TAG_EXPRESSION , DEFAULT_BEFORE_ORDER )(body)
35- }
33+ private object HookType {
3634
37- def Before (tagExpression : String )(body : HookBody ): Unit = {
38- Before (tagExpression, DEFAULT_BEFORE_ORDER )(body)
39- }
35+ case object BEFORE extends HookType
4036
41- def Before (order : Int )(body : HookBody ): Unit = {
42- Before (EMPTY_TAG_EXPRESSION , order)(body)
43- }
37+ case object BEFORE_STEP extends HookType
4438
45- def Before (tagExpression : String , order : Int )(body : HookBody ): Unit = {
46- registry.beforeHooks += ScalaHookDetails (tagExpression, order, body)
47- }
39+ case object AFTER extends HookType
4840
49- def BeforeStep (body : HookBody ): Unit = {
50- BeforeStep (EMPTY_TAG_EXPRESSION , DEFAULT_BEFORE_ORDER )(body)
51- }
41+ case object AFTER_STEP extends HookType
5242
53- def BeforeStep (tagExpression : String )(body : HookBody ): Unit = {
54- BeforeStep (tagExpression, DEFAULT_BEFORE_ORDER )(body)
5543 }
5644
57- def BeforeStep (order : Int )(body : HookBody ): Unit = {
58- BeforeStep (EMPTY_TAG_EXPRESSION , order)(body)
59- }
45+ def Before : HookBody = Before (EMPTY_TAG_EXPRESSION , DEFAULT_BEFORE_ORDER )
6046
61- def BeforeStep (tagExpression : String , order : Int )(body : HookBody ): Unit = {
62- registry.beforeStepHooks += ScalaHookDetails (tagExpression, order, body)
63- }
47+ def Before (tagExpression : String ): HookBody = Before (tagExpression, DEFAULT_BEFORE_ORDER )
6448
65- def After (body : HookBody ): Unit = {
66- After (EMPTY_TAG_EXPRESSION , DEFAULT_AFTER_ORDER )(body)
67- }
49+ def Before (order : Int ): HookBody = Before (EMPTY_TAG_EXPRESSION , order)
6850
69- def After (tagExpression : String )(body : HookBody ): Unit = {
70- After (tagExpression, DEFAULT_AFTER_ORDER )(body)
71- }
51+ def Before (tagExpression : String , order : Int ): HookBody = new HookBody (HookType .BEFORE , tagExpression, order)
7252
73- def After (order : Int )(body : HookBody ): Unit = {
74- After (EMPTY_TAG_EXPRESSION , order)(body)
75- }
53+ def BeforeStep : HookBody = BeforeStep (EMPTY_TAG_EXPRESSION , DEFAULT_BEFORE_ORDER )
7654
77- def After (tagExpression : String , order : Int )(body : HookBody ): Unit = {
78- registry.afterHooks += ScalaHookDetails (tagExpression, order, body)
79- }
55+ def BeforeStep (tagExpression : String ): HookBody = BeforeStep (tagExpression, DEFAULT_BEFORE_ORDER )
8056
81- def AfterStep (body : HookBody ): Unit = {
82- AfterStep (EMPTY_TAG_EXPRESSION , DEFAULT_AFTER_ORDER )(body)
83- }
57+ def BeforeStep (order : Int ): HookBody = BeforeStep (EMPTY_TAG_EXPRESSION , order)
8458
85- def AfterStep (tagExpression : String )(body : HookBody ): Unit = {
86- AfterStep (tagExpression, DEFAULT_AFTER_ORDER )(body)
87- }
59+ def BeforeStep (tagExpression : String , order : Int ): HookBody = new HookBody (HookType .BEFORE_STEP , tagExpression, order)
8860
89- def AfterStep (order : Int )(body : HookBody ): Unit = {
90- AfterStep (EMPTY_TAG_EXPRESSION , order)(body)
91- }
61+ def After : HookBody = After (EMPTY_TAG_EXPRESSION , DEFAULT_AFTER_ORDER )
62+
63+ def After (tagExpression : String ): HookBody = After (tagExpression, DEFAULT_AFTER_ORDER )
64+
65+ def After (order : Int ): HookBody = After (EMPTY_TAG_EXPRESSION , order)
66+
67+ def After (tagExpression : String , order : Int ): HookBody = new HookBody (HookType .AFTER , tagExpression, order)
68+
69+ def AfterStep : HookBody = AfterStep (EMPTY_TAG_EXPRESSION , DEFAULT_AFTER_ORDER )
70+
71+ def AfterStep (tagExpression : String ): HookBody = AfterStep (tagExpression, DEFAULT_AFTER_ORDER )
72+
73+ def AfterStep (order : Int ): HookBody = AfterStep (EMPTY_TAG_EXPRESSION , order)
74+
75+ def AfterStep (tagExpression : String , order : Int ): HookBody = new HookBody (HookType .AFTER_STEP , tagExpression, order)
76+
77+ final class HookBody (hookType : HookType , tagExpression : String , order : Int ) {
78+
79+ def apply (body : => Unit ): Unit = {
80+ apply(_ => body)
81+ }
82+
83+ def apply (body : Scenario => Unit ): Unit = {
84+ val details = ScalaHookDetails (tagExpression, order, body)
85+ hookType match {
86+ case HookType .BEFORE =>
87+ registry.beforeHooks += details
88+ case HookType .BEFORE_STEP =>
89+ registry.beforeStepHooks += details
90+ case HookType .AFTER =>
91+ registry.afterHooks += details
92+ case HookType .AFTER_STEP =>
93+ registry.afterStepHooks += details
94+ }
95+ }
9296
93- def AfterStep (tagExpression : String , order : Int )(body : HookBody ): Unit = {
94- registry.afterStepHooks += ScalaHookDetails (tagExpression, order, body)
9597 }
9698
9799}
0 commit comments