Skip to content

Commit 2bae24d

Browse files
authored
Merge pull request #28 from cucumber/feature/26
Complete the doc to highlight that no parameter hooks work fine
2 parents 5e55869 + 2096300 commit 2bae24d

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

docs/hooks.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Scenario hooks run for every scenario.
1414
`Before` hooks run before the first step of each scenario.
1515

1616
```scala
17-
Before { scenario : Scenario =>
17+
Before {
1818
// Do something before each scenario
1919
}
2020
```
@@ -24,7 +24,7 @@ Before { scenario : Scenario =>
2424
`After` hooks run after the last step of each scenario.
2525

2626
```scala
27-
After { scenario : Scenario =>
27+
After {
2828
// Do something after each scenario
2929
}
3030
```
@@ -36,25 +36,36 @@ Step hooks invoked before and after a step.
3636
### BeforeStep
3737

3838
```scala
39-
BeforeStep { scenario : Scenario =>
39+
BeforeStep {
4040
// Do something before step
4141
}
4242
```
4343

4444
### AfterStep
4545

4646
```scala
47-
AfterStep { scenario : Scenario =>
47+
AfterStep {
4848
// Do something after step
4949
}
5050
```
5151

52+
## Scenario parameter
53+
54+
The scenario is available as parameter in all hooks.
55+
56+
You can use it like this:
57+
```scala
58+
Before { scenario : Scenario =>
59+
// Do something with the scenario
60+
}
61+
```
62+
5263
## Conditional hooks
5364

5465
Hooks can be conditionally selected for execution based on the tags of the scenario.
5566

5667
```scala
57-
Before("@browser and not @headless") { _ =>
68+
Before("@browser and not @headless") {
5869
// Do something before each scenario with tag @browser but not @headless
5970
}
6071
```
@@ -64,11 +75,11 @@ Before("@browser and not @headless") { _ =>
6475
You can define an order between multiple hooks.
6576

6677
```scala
67-
Before(10) { _ =>
78+
Before(10) {
6879
// Do something before each scenario
6980
}
7081

71-
Before(20) { _ =>
82+
Before(20) {
7283
// Do something before each scenario
7384
}
7485
```
@@ -79,7 +90,7 @@ The **default order is 1000**.
7990

8091
You mix up conditional and order hooks with following syntax:
8192
```scala
82-
Before("@browser and not @headless", 10) { _ =>
93+
Before("@browser and not @headless", 10) {
8394
// Do something before each scenario
8495
}
8596
```

scala/sources/src/main/scala/io/cucumber/scala/ScalaDsl.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package io.cucumber.scala
22

33
import java.lang.reflect.{ParameterizedType, Type}
44

5-
import io.cucumber.core.backend.{HookDefinition, StepDefinition}
65
import io.cucumber.scala.Aliases.HookBody
76

8-
import scala.collection.mutable.ArrayBuffer
9-
107
/**
118
* Base trait for a scala step definition implementation.
129
*/
@@ -21,8 +18,6 @@ trait ScalaDsl {
2118

2219
val registry = new ScalaDslRegistry()
2320

24-
// TODO support Before/After with no parameter
25-
2621
def Before(body: HookBody): Unit = {
2722
Before(EMPTY_TAG_EXPRESSION, DEFAULT_BEFORE_ORDER)(body)
2823
}

0 commit comments

Comments
 (0)