@@ -22,21 +22,22 @@ trait ScalaDsl extends BaseScalaDsl with StepDsl with HookDsl with DataTableType
22
22
23
23
}
24
24
25
- private [scala] trait HookDsl extends BaseScalaDsl {
25
+ sealed trait HookType
26
26
27
- private sealed trait HookType
27
+ object HookType {
28
28
29
- private object HookType {
29
+ case object BEFORE extends HookType
30
30
31
- case object BEFORE extends HookType
31
+ case object BEFORE_STEP extends HookType
32
32
33
- case object BEFORE_STEP extends HookType
33
+ case object AFTER extends HookType
34
34
35
- case object AFTER extends HookType
35
+ case object AFTER_STEP extends HookType
36
36
37
- case object AFTER_STEP extends HookType
37
+ }
38
38
39
- }
39
+ private [scala] trait HookDsl extends BaseScalaDsl {
40
+ self =>
40
41
41
42
/**
42
43
* Defines an before hook.
@@ -63,7 +64,7 @@ private[scala] trait HookDsl extends BaseScalaDsl {
63
64
* @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed
64
65
* @param order the order in which this hook should run. Higher numbers are run first
65
66
*/
66
- def Before (tagExpression : String , order : Int ) = new HookBody (HookType .BEFORE , tagExpression, order)
67
+ def Before (tagExpression : String , order : Int ) = new HookBody (HookType .BEFORE , tagExpression, order, Utils .frame(self) )
67
68
68
69
/**
69
70
* Defines an before step hook.
@@ -90,7 +91,7 @@ private[scala] trait HookDsl extends BaseScalaDsl {
90
91
* @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed
91
92
* @param order the order in which this hook should run. Higher numbers are run first
92
93
*/
93
- def BeforeStep (tagExpression : String , order : Int ) = new HookBody (HookType .BEFORE_STEP , tagExpression, order)
94
+ def BeforeStep (tagExpression : String , order : Int ) = new HookBody (HookType .BEFORE_STEP , tagExpression, order, Utils .frame(self) )
94
95
95
96
/**
96
97
* Defines and after hook.
@@ -117,7 +118,7 @@ private[scala] trait HookDsl extends BaseScalaDsl {
117
118
* @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed
118
119
* @param order the order in which this hook should run. Higher numbers are run first
119
120
*/
120
- def After (tagExpression : String , order : Int ) = new HookBody (HookType .AFTER , tagExpression, order)
121
+ def After (tagExpression : String , order : Int ) = new HookBody (HookType .AFTER , tagExpression, order, Utils .frame(self) )
121
122
122
123
/**
123
124
* Defines and after step hook.
@@ -144,26 +145,21 @@ private[scala] trait HookDsl extends BaseScalaDsl {
144
145
* @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed
145
146
* @param order the order in which this hook should run. Higher numbers are run first
146
147
*/
147
- def AfterStep (tagExpression : String , order : Int ) = new HookBody (HookType .AFTER_STEP , tagExpression, order)
148
+ def AfterStep (tagExpression : String , order : Int ) = new HookBody (HookType .AFTER_STEP , tagExpression, order, Utils .frame(self))
149
+
150
+ final class HookBody (hookType : HookType , tagExpression : String , order : Int , frame : StackTraceElement ) {
148
151
149
- final class HookBody (hookType : HookType , tagExpression : String , order : Int ) {
152
+ // When a HookBody is created, we want to ensure that the apply method is called
153
+ // To be able to check this, we notice the registry to expect a hook
154
+ registry.expectHook(hookType, frame)
150
155
151
156
def apply (body : => Unit ): Unit = {
152
157
apply(_ => body)
153
158
}
154
159
155
160
def apply (body : Scenario => Unit ): Unit = {
156
161
val details = ScalaHookDetails (tagExpression, order, body)
157
- hookType match {
158
- case HookType .BEFORE =>
159
- registry.beforeHooks += details
160
- case HookType .BEFORE_STEP =>
161
- registry.beforeStepHooks += details
162
- case HookType .AFTER =>
163
- registry.afterHooks += details
164
- case HookType .AFTER_STEP =>
165
- registry.afterStepHooks += details
166
- }
162
+ registry.registerHook(hookType, details, frame)
167
163
}
168
164
169
165
}
@@ -181,7 +177,7 @@ private[scala] trait DocStringTypeDsl extends BaseScalaDsl {
181
177
* @tparam T type to convert to
182
178
*/
183
179
def DocStringType [T ](contentType : String )(body : DocStringDefinitionBody [T ])(implicit ev : ClassTag [T ]): Unit = {
184
- registry.docStringTypes += ScalaDocStringTypeDetails [T ](contentType, body, ev)
180
+ registry.registerDocStringType( ScalaDocStringTypeDetails [T ](contentType, body, ev) )
185
181
}
186
182
187
183
}
@@ -209,19 +205,19 @@ private[scala] trait DataTableTypeDsl extends BaseScalaDsl {
209
205
final class DataTableTypeBody (replaceWithEmptyString : Seq [String ]) {
210
206
211
207
def apply [T ](body : DataTableEntryDefinitionBody [T ])(implicit ev : ClassTag [T ]): Unit = {
212
- registry.dataTableTypes += ScalaDataTableEntryTypeDetails [T ](replaceWithEmptyString, body, ev)
208
+ registry.registerDataTableType( ScalaDataTableEntryTypeDetails [T ](replaceWithEmptyString, body, ev) )
213
209
}
214
210
215
211
def apply [T ](body : DataTableRowDefinitionBody [T ])(implicit ev : ClassTag [T ]): Unit = {
216
- registry.dataTableTypes += ScalaDataTableRowTypeDetails [T ](replaceWithEmptyString, body, ev)
212
+ registry.registerDataTableType( ScalaDataTableRowTypeDetails [T ](replaceWithEmptyString, body, ev) )
217
213
}
218
214
219
215
def apply [T ](body : DataTableCellDefinitionBody [T ])(implicit ev : ClassTag [T ]): Unit = {
220
- registry.dataTableTypes += ScalaDataTableCellTypeDetails [T ](replaceWithEmptyString, body, ev)
216
+ registry.registerDataTableType( ScalaDataTableCellTypeDetails [T ](replaceWithEmptyString, body, ev) )
221
217
}
222
218
223
219
def apply [T ](body : DataTableDefinitionBody [T ])(implicit ev : ClassTag [T ]): Unit = {
224
- registry.dataTableTypes += ScalaDataTableTableTypeDetails [T ](replaceWithEmptyString, body, ev)
220
+ registry.registerDataTableType( ScalaDataTableTableTypeDetails [T ](replaceWithEmptyString, body, ev) )
225
221
}
226
222
227
223
}
@@ -398,7 +394,7 @@ private[scala] trait ParameterTypeDsl extends BaseScalaDsl {
398
394
}
399
395
400
396
private def register [R ](pf : PartialFunction [List [String ], R ])(implicit tag : ClassTag [R ]): Unit = {
401
- registry.parameterTypes += ScalaParameterTypeDetails [R ](name, regex, pf, tag)
397
+ registry.registerParameterType( ScalaParameterTypeDetails [R ](name, regex, pf, tag) )
402
398
}
403
399
404
400
}
@@ -413,7 +409,7 @@ private[scala] trait DefaultTransformerDsl extends BaseScalaDsl {
413
409
* @param body converts `String` argument to an instance of the `Type` argument
414
410
*/
415
411
def DefaultParameterTransformer (body : DefaultParameterTransformerBody ): Unit = {
416
- registry.defaultParameterTransformers += ScalaDefaultParameterTransformerDetails (body)
412
+ registry.registerDefaultParameterTransformer( ScalaDefaultParameterTransformerDetails (body) )
417
413
}
418
414
419
415
/**
@@ -441,7 +437,7 @@ private[scala] trait DefaultTransformerDsl extends BaseScalaDsl {
441
437
}
442
438
443
439
private def DefaultDataTableCellTransformer (replaceWithEmptyString : Seq [String ])(body : DefaultDataTableCellTransformerBody ): Unit = {
444
- registry.defaultDataTableCellTransformers += ScalaDefaultDataTableCellTransformerDetails (replaceWithEmptyString, body)
440
+ registry.registerDefaultDataTableCellTransformer( ScalaDefaultDataTableCellTransformerDetails (replaceWithEmptyString, body) )
445
441
}
446
442
447
443
/**
@@ -468,7 +464,7 @@ private[scala] trait DefaultTransformerDsl extends BaseScalaDsl {
468
464
}
469
465
470
466
private def DefaultDataTableEntryTransformer (replaceWithEmptyString : Seq [String ])(body : DefaultDataTableEntryTransformerBody ): Unit = {
471
- registry.defaultDataTableEntryTransformers += ScalaDefaultDataTableEntryTransformerDetails (replaceWithEmptyString, body)
467
+ registry.registerDefaultDataTableEntryTransformer( ScalaDefaultDataTableEntryTransformerDetails (replaceWithEmptyString, body) )
472
468
}
473
469
474
470
}
@@ -911,7 +907,7 @@ private[scala] trait StepDsl extends BaseScalaDsl {
911
907
}
912
908
913
909
private def register (manifests : Manifest [_ <: Any ]* )(pf : PartialFunction [List [Any ], Any ]): Unit = {
914
- registry.stepDefinitions += ScalaStepDetails (Utils .frame(self), name, regex, manifests, pf)
910
+ registry.registerStep( ScalaStepDetails (Utils .frame(self), name, regex, manifests, pf) )
915
911
}
916
912
917
913
}
0 commit comments