@@ -2,7 +2,7 @@ package io.cucumber.scala
2
2
3
3
import java .lang .reflect .{ParameterizedType , Type }
4
4
5
- import io .cucumber .scala .Aliases .{ DefaultDataTableCellTransformerBody , DefaultDataTableEntryTransformerBody , DefaultParameterTransformerBody , DocStringDefinitionBody , HookBody }
5
+ import io .cucumber .scala .Aliases ._
6
6
7
7
import scala .reflect .ClassTag
8
8
@@ -28,70 +28,72 @@ trait ScalaDsl extends BaseScalaDsl with StepDsl with HookDsl with DataTableType
28
28
29
29
private [scala] trait HookDsl extends BaseScalaDsl {
30
30
31
- // TODO support Before/After with no parameter
31
+ private sealed trait HookType
32
32
33
- def Before (body : HookBody ): Unit = {
34
- Before (EMPTY_TAG_EXPRESSION , DEFAULT_BEFORE_ORDER )(body)
35
- }
33
+ private object HookType {
36
34
37
- def Before (tagExpression : String )(body : HookBody ): Unit = {
38
- Before (tagExpression, DEFAULT_BEFORE_ORDER )(body)
39
- }
35
+ case object BEFORE extends HookType
40
36
41
- def Before (order : Int )(body : HookBody ): Unit = {
42
- Before (EMPTY_TAG_EXPRESSION , order)(body)
43
- }
37
+ case object BEFORE_STEP extends HookType
44
38
45
- def Before (tagExpression : String , order : Int )(body : HookBody ): Unit = {
46
- registry.beforeHooks += ScalaHookDetails (tagExpression, order, body)
47
- }
39
+ case object AFTER extends HookType
48
40
49
- def BeforeStep (body : HookBody ): Unit = {
50
- BeforeStep (EMPTY_TAG_EXPRESSION , DEFAULT_BEFORE_ORDER )(body)
51
- }
41
+ case object AFTER_STEP extends HookType
52
42
53
- def BeforeStep (tagExpression : String )(body : HookBody ): Unit = {
54
- BeforeStep (tagExpression, DEFAULT_BEFORE_ORDER )(body)
55
43
}
56
44
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 )
60
46
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 )
64
48
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)
68
50
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)
72
52
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 )
76
54
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 )
80
56
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)
84
58
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)
88
60
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
+ }
92
96
93
- def AfterStep (tagExpression : String , order : Int )(body : HookBody ): Unit = {
94
- registry.afterStepHooks += ScalaHookDetails (tagExpression, order, body)
95
97
}
96
98
97
99
}
0 commit comments