Skip to content

Commit 43ee9c8

Browse files
committed
Make sure Background steps are reported under the scenario they belong to. See #276
1 parent d89f20a commit 43ee9c8

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

core/src/main/java/cucumber/runtime/model/CucumberScenario.java

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public CucumberScenario(CucumberFeature cucumberFeature, CucumberBackground cucu
1919
this.cucumberBackground = cucumberBackground;
2020
}
2121

22+
public CucumberBackground getCucumberBackground() {
23+
return cucumberBackground;
24+
}
25+
2226
/**
2327
* This method is called when Cucumber is run from the CLI, but not when run from JUnit
2428
*/

junit/src/main/java/cucumber/junit/ExecutionUnitRunner.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ public String getName() {
4545
public Description getDescription() {
4646
if (description == null) {
4747
description = createDescription(getName(), cucumberScenario);
48-
for (Step child : getChildren()) {
49-
description.addChild(describeChild(child));
48+
49+
if(cucumberScenario.getCucumberBackground() != null) {
50+
for (Step backgroundStep : cucumberScenario.getCucumberBackground().getSteps()) {
51+
description.addChild(describeChild(backgroundStep));
52+
}
53+
}
54+
55+
for (Step step : getChildren()) {
56+
description.addChild(describeChild(step));
5057
}
5158
}
5259
return description;

picocontainer/src/test/resources/.cucumber/stepdefs.json

+32-8
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@
6464
{
6565
"source": "^I want to recognize colors as enums$",
6666
"flags": "",
67-
"steps": [
68-
{
69-
"name": "I want to recognize colors as enums",
70-
"args": []
71-
}
72-
]
67+
"steps": []
7368
},
7469
{
7570
"source": "^i use the (.*) in a step$",
@@ -104,7 +99,17 @@
10499
{
105100
"source": "^the date is (.+)$",
106101
"flags": "",
107-
"steps": []
102+
"steps": [
103+
{
104+
"name": "the date is 2011/10/25",
105+
"args": [
106+
{
107+
"offset": 12,
108+
"val": "2011/10/25"
109+
}
110+
]
111+
}
112+
]
108113
},
109114
{
110115
"source": "^the date should be (.+)$",
@@ -118,6 +123,15 @@
118123
"val": "Mar 1 2012"
119124
}
120125
]
126+
},
127+
{
128+
"name": "the date should be Oct 25 2011",
129+
"args": [
130+
{
131+
"offset": 19,
132+
"val": "Oct 25 2011"
133+
}
134+
]
121135
}
122136
]
123137
},
@@ -139,7 +153,17 @@
139153
{
140154
"source": "^the iso date is (.+)$",
141155
"flags": "",
142-
"steps": []
156+
"steps": [
157+
{
158+
"name": "the iso date is 2012-03-01T06:54:14",
159+
"args": [
160+
{
161+
"offset": 16,
162+
"val": "2012-03-01T06:54:14"
163+
}
164+
]
165+
}
166+
]
143167
},
144168
{
145169
"source": "^there are (\\d+) cukes in my belly",

picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/dates.feature

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Feature: Dates
2-
# Scenario: A pretty date
3-
# Given the date is 2011/10/25
4-
# Then the date should be Oct 25 2011
2+
Scenario: A pretty date
3+
Given the date is 2011/10/25
4+
Then the date should be Oct 25 2011
55

6-
# Scenario: An ISO 8601 date
7-
# Given the iso date is 2012-03-01T06:54:14
8-
# Then the date should be Mar 1 2012
6+
Scenario: An ISO 8601 date
7+
Given the iso date is 2012-03-01T06:54:14
8+
Then the date should be Mar 1 2012
99

1010
Scenario: An ISO 8601 date as Calendar
1111
Given the iso calendar is 2012-03-01T06:54:14

picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/enums.feature

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Feature: Java Enums
22

3-
Scenario Outline: color should be recognized as an enum
3+
Background:
44
Given I want to recognize colors as enums
5+
6+
Scenario Outline: color should be recognized as an enum
57
When i use the <color> in a step
68
Then it should be recognized as enum
79

0 commit comments

Comments
 (0)