4
4
import gherkin .formatter .model .DataTableRow ;
5
5
import gherkin .formatter .model .DocString ;
6
6
import gherkin .formatter .model .ExamplesTableRow ;
7
+ import gherkin .formatter .model .ScenarioOutline ;
7
8
import gherkin .formatter .model .Step ;
9
+ import gherkin .formatter .model .Tag ;
8
10
import org .junit .Test ;
9
11
10
12
import java .util .ArrayList ;
13
+ import java .util .Collections ;
11
14
import java .util .List ;
12
15
13
16
import static java .util .Arrays .asList ;
14
17
import static org .junit .Assert .assertEquals ;
15
18
16
19
public class CucumberScenarioOutlineTest {
17
20
private static final List <Comment > C = new ArrayList <Comment >();
21
+ private static final List <Tag > T = Collections .<Tag >emptyList ();
18
22
19
23
@ Test
20
24
public void replaces_tokens_in_step_names () {
@@ -38,5 +42,41 @@ public void replaces_tokens_in_data_tables() {
38
42
39
43
Step exampleStep = CucumberScenarioOutline .createExampleStep (outlineStep , new ExamplesTableRow (C , asList ("n" ), 1 , "" ), new ExamplesTableRow (C , asList ("10" ), 1 , "" ));
40
44
assertEquals (asList ("I" , "have 10 cukes" ), exampleStep .getRows ().get (0 ).getCells ());
41
- }
45
+ }
46
+
47
+ /***
48
+ * From a scenario outline, we create one or more "Example Scenario"s. This is composed
49
+ * of each step from the outline, with the tokens replaced with the pertient values
50
+ * for the current example row. <p />
51
+ *
52
+ * Each "Example Scenario" has a name. This was previously just a copy of the outline's
53
+ * name. However, we'd like to be able to support token replacement in the scenario too,
54
+ * for example:
55
+ *
56
+ * <pre>
57
+ * Scenario Outline: Time offset check for <LOCATION_NAME>
58
+ * Given my local country is <LOCATION_NAME>
59
+ * When I compare the time difference to GMT
60
+ * Then the time offset should be <OFFSET>
61
+ *
62
+ * Examples:
63
+ * | LOCATION_NAME | OFFSET |
64
+ * | London | 1 |
65
+ * | San Fran | 8 |
66
+ * </pre>
67
+ *
68
+ * Will create a scenario named "Time offset check for London" for the first row in the
69
+ * examples table.
70
+ */
71
+ @ Test
72
+ public void replaces_tokens_in_scenario_names () {
73
+ // Create Gherkin the outline itself ...
74
+ ScenarioOutline outline = new ScenarioOutline (C , T ,"Scenario Outline" , "Time offset check for <LOCATION_NAME>" , "" , new Integer (1 ), "" );
75
+
76
+ // ... then the Cukes implementation
77
+ CucumberScenarioOutline cukeOutline = new CucumberScenarioOutline (null , null , outline );
78
+ CucumberScenario exampleScenario = cukeOutline .createExampleScenario (new ExamplesTableRow (C , asList ("LOCATION_NAME" ), 1 , "" ), new ExamplesTableRow (C , asList ("London" ), 1 , "" ), T );
79
+
80
+ assertEquals ("Time offset check for London" , exampleScenario .getGherkinModel ().getName ());
81
+ }
42
82
}
0 commit comments