Skip to content

Commit 70f7775

Browse files
committed
closes #92
1 parent e82f88d commit 70f7775

File tree

4 files changed

+127
-14
lines changed

4 files changed

+127
-14
lines changed

features/outline.feature

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,55 @@ Feature: run outline
9898
"""
9999
a failing step
100100
"""
101+
102+
Scenario: should translate step table body
103+
Given a feature "normal.feature" file:
104+
"""
105+
Feature: outline
106+
107+
Background:
108+
Given I'm listening to suite events
109+
110+
Scenario Outline: run with events
111+
Given a feature path "<path>"
112+
When I run feature suite
113+
Then these events had to be fired for a number of times:
114+
| BeforeScenario | <scen> |
115+
| BeforeStep | <step> |
116+
117+
Examples:
118+
| path | scen | step |
119+
| features/load.feature:6 | 1 | 3 |
120+
| features/load.feature | 6 | 19 |
121+
"""
122+
When I run feature suite
123+
Then the suite should have passed
124+
And the following steps should be passed:
125+
"""
126+
I'm listening to suite events
127+
I run feature suite
128+
a feature path "features/load.feature:6"
129+
a feature path "features/load.feature"
130+
"""
131+
132+
Scenario Outline: should translate step doc string argument
133+
Given a feature "normal.feature" file:
134+
"""
135+
Feature: scenario events
136+
137+
Background:
138+
Given I'm listening to suite events
139+
140+
Scenario: run with events
141+
Given a feature path "<path>"
142+
When I run feature suite
143+
Then these events had to be fired for a number of times:
144+
| BeforeScenario | <scen> |
145+
"""
146+
When I run feature suite
147+
Then the suite should have passed
148+
149+
Examples:
150+
| path | scen |
151+
| features/load.feature:6 | 1 |
152+
| features/load.feature | 6 |

fmt_pretty.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ type pretty struct {
3838
outline *gherkin.ScenarioOutline
3939

4040
// state
41-
bgSteps int
42-
steps int
43-
commentPos int
41+
bgSteps int
42+
totalBgSteps int
43+
steps int
44+
commentPos int
4445

4546
// whether scenario or scenario outline keyword was printed
4647
scenarioKeyword bool
@@ -68,8 +69,10 @@ func (f *pretty) Feature(ft *gherkin.Feature, p string, c []byte) {
6869
f.scenario = nil
6970
f.outline = nil
7071
f.bgSteps = 0
72+
f.totalBgSteps = 0
7173
if ft.Background != nil {
7274
f.bgSteps = len(ft.Background.Steps)
75+
f.totalBgSteps = len(ft.Background.Steps)
7376
}
7477
}
7578

@@ -84,15 +87,15 @@ func (f *pretty) Node(node interface{}) {
8487
case *gherkin.Scenario:
8588
f.scenario = t
8689
f.outline = nil
87-
f.steps = len(t.Steps) + f.bgSteps
90+
f.steps = len(t.Steps) + f.totalBgSteps
8891
f.scenarioKeyword = false
8992
case *gherkin.ScenarioOutline:
9093
f.outline = t
9194
f.scenario = nil
9295
f.outlineNumExample = -1
9396
f.scenarioKeyword = false
9497
case *gherkin.TableRow:
95-
f.steps = len(f.outline.Steps) + f.bgSteps
98+
f.steps = len(f.outline.Steps) + f.totalBgSteps
9699
f.outlineSteps = []*stepResult{}
97100
}
98101
}
@@ -157,10 +160,10 @@ func (f *pretty) printOutlineExample(outline *gherkin.ScenarioOutline) {
157160
case res.typ == skipped && clr == nil:
158161
clr = cyan
159162
}
160-
if printSteps {
163+
if printSteps && i >= f.totalBgSteps {
161164
// in first example, we need to print steps
162165
var text string
163-
ostep := outline.Steps[i]
166+
ostep := outline.Steps[i-f.totalBgSteps]
164167
if res.def != nil {
165168
if m := outlinePlaceholderRegexp.FindAllStringIndex(ostep.Text, -1); len(m) > 0 {
166169
var pos int
@@ -180,6 +183,23 @@ func (f *pretty) printOutlineExample(outline *gherkin.ScenarioOutline) {
180183
}
181184
// print the step outline
182185
fmt.Fprintln(f.out, s(f.indent*2)+cyan(strings.TrimSpace(ostep.Keyword))+" "+text)
186+
187+
// print step argument
188+
// @TODO: need to make example header cells bold
189+
switch t := ostep.Argument.(type) {
190+
case *gherkin.DataTable:
191+
f.printTable(t, cyan)
192+
case *gherkin.DocString:
193+
var ct string
194+
if len(t.ContentType) > 0 {
195+
ct = " " + cyan(t.ContentType)
196+
}
197+
fmt.Fprintln(f.out, s(f.indent*3)+cyan(t.Delimitter)+ct)
198+
for _, ln := range strings.Split(t.Content, "\n") {
199+
fmt.Fprintln(f.out, s(f.indent*3)+cyan(ln))
200+
}
201+
fmt.Fprintln(f.out, s(f.indent*3)+cyan(t.Delimitter))
202+
}
183203
}
184204
}
185205

@@ -256,6 +276,11 @@ func (f *pretty) printStep(step *gherkin.Step, def *StepDef, c colors.ColorFunc)
256276
}
257277

258278
func (f *pretty) printStepKind(res *stepResult) {
279+
f.steps--
280+
if f.outline != nil {
281+
f.outlineSteps = append(f.outlineSteps, res)
282+
}
283+
259284
// if has not printed background yet
260285
switch {
261286
// first background step
@@ -281,12 +306,8 @@ func (f *pretty) printStepKind(res *stepResult) {
281306
fmt.Fprintln(f.out, "\n"+text)
282307
f.scenarioKeyword = true
283308
}
284-
f.steps--
285309
// first step of outline scenario, print header and calculate comment position
286310
case f.outline != nil:
287-
f.outlineSteps = append(f.outlineSteps, res)
288-
f.steps--
289-
290311
// print scenario keyword and value if first example
291312
if !f.scenarioKeyword {
292313
f.commentPos = f.longestStep(f.outline.Steps, f.length(f.outline))
@@ -300,7 +321,7 @@ func (f *pretty) printStepKind(res *stepResult) {
300321
fmt.Fprintln(f.out, "\n"+text)
301322
f.scenarioKeyword = true
302323
}
303-
if len(f.outlineSteps) == len(f.outline.Steps)+f.bgSteps {
324+
if len(f.outlineSteps) == len(f.outline.Steps)+f.totalBgSteps {
304325
// an outline example steps has went through
305326
f.printOutlineExample(f.outline)
306327
f.outlineNumExamples--

godog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ Godog was inspired by Behat and Cucumber the above description is taken from it'
3939
package godog
4040

4141
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
42-
const Version = "v0.7.2"
42+
const Version = "v0.7.3"

suite.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,52 @@ func (s *Suite) runOutline(outline *gherkin.ScenarioOutline, b *gherkin.Backgrou
405405
for i, placeholder := range placeholders {
406406
text = strings.Replace(text, "<"+placeholder.Value+">", group.Cells[i].Value, -1)
407407
}
408+
409+
// translate argument
410+
arg := outlineStep.Argument
411+
switch t := outlineStep.Argument.(type) {
412+
case *gherkin.DataTable:
413+
tbl := &gherkin.DataTable{
414+
Node: t.Node,
415+
Rows: make([]*gherkin.TableRow, len(t.Rows)),
416+
}
417+
for i, row := range t.Rows {
418+
cells := make([]*gherkin.TableCell, len(row.Cells))
419+
for j, cell := range row.Cells {
420+
trans := cell.Value
421+
for i, placeholder := range placeholders {
422+
trans = strings.Replace(trans, "<"+placeholder.Value+">", group.Cells[i].Value, -1)
423+
}
424+
cells[j] = &gherkin.TableCell{
425+
Node: cell.Node,
426+
Value: trans,
427+
}
428+
}
429+
tbl.Rows[i] = &gherkin.TableRow{
430+
Node: row.Node,
431+
Cells: cells,
432+
}
433+
}
434+
arg = tbl
435+
case *gherkin.DocString:
436+
trans := t.Content
437+
for i, placeholder := range placeholders {
438+
trans = strings.Replace(trans, "<"+placeholder.Value+">", group.Cells[i].Value, -1)
439+
}
440+
arg = &gherkin.DocString{
441+
Node: t.Node,
442+
Content: trans,
443+
ContentType: t.ContentType,
444+
Delimitter: t.Delimitter,
445+
}
446+
}
447+
408448
// clone a step
409449
step := &gherkin.Step{
410450
Node: outlineStep.Node,
411451
Text: text,
412452
Keyword: outlineStep.Keyword,
413-
Argument: outlineStep.Argument,
453+
Argument: arg,
414454
}
415455
steps = append(steps, step)
416456
}

0 commit comments

Comments
 (0)