Skip to content

Commit 6b2d813

Browse files
committed
fixes outline example printer, fixes #47
1 parent 409db5f commit 6b2d813

File tree

4 files changed

+39
-44
lines changed

4 files changed

+39
-44
lines changed

examples/api/version.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Feature: get version
2020
And the response should match json:
2121
"""
2222
{
23-
"version": "v0.5.0"
23+
"version": "v0.5.3"
2424
}
2525
"""

fmt.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,10 @@ type basefmt struct {
145145

146146
func (f *basefmt) Node(n interface{}) {
147147
switch t := n.(type) {
148-
case *gherkin.ScenarioOutline:
148+
case *gherkin.TableRow:
149149
f.owner = t
150150
case *gherkin.Scenario:
151151
f.owner = t
152-
case *gherkin.Background:
153-
f.owner = t
154152
}
155153
}
156154

fmt_pretty.go

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type pretty struct {
3636
steps int
3737
commentPos int
3838

39+
// whether scenario or scenario outline keyword was printed
40+
scenarioKeyword bool
41+
3942
// outline
4043
outlineSteps []*stepResult
4144
outlineNumExample int
@@ -75,12 +78,16 @@ func (f *pretty) Node(node interface{}) {
7578
case *gherkin.Scenario:
7679
f.scenario = t
7780
f.outline = nil
78-
f.steps = len(t.Steps)
81+
f.steps = len(t.Steps) + f.bgSteps
82+
f.scenarioKeyword = false
7983
case *gherkin.ScenarioOutline:
8084
f.outline = t
8185
f.scenario = nil
82-
f.steps = len(t.Steps)
8386
f.outlineNumExample = -1
87+
f.scenarioKeyword = false
88+
case *gherkin.TableRow:
89+
f.steps = len(f.outline.Steps) + f.bgSteps
90+
f.outlineSteps = []*stepResult{}
8491
}
8592
}
8693

@@ -237,8 +244,6 @@ func (f *pretty) printStep(step *gherkin.Step, def *StepDef, c color) {
237244
}
238245

239246
func (f *pretty) printStepKind(res *stepResult) {
240-
_, isBgStep := res.owner.(*gherkin.Background)
241-
242247
// if has not printed background yet
243248
switch {
244249
// first background step
@@ -249,51 +254,43 @@ func (f *pretty) printStepKind(res *stepResult) {
249254
// subsequent background steps
250255
case f.bgSteps > 0:
251256
f.bgSteps--
252-
// a background step for another scenario, but all bg steps are
253-
// already printed. so just skip it
254-
case isBgStep:
255-
return
256257
// first step of scenario, print header and calculate comment position
257-
case f.scenario != nil && f.steps == len(f.scenario.Steps):
258-
f.commentPos = f.longestStep(f.scenario.Steps, f.length(f.scenario))
259-
if f.feature.Background != nil {
260-
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
261-
f.commentPos = bgLen
258+
case f.scenario != nil:
259+
// print scenario keyword and value if first example
260+
if !f.scenarioKeyword {
261+
f.commentPos = f.longestStep(f.scenario.Steps, f.length(f.scenario))
262+
if f.feature.Background != nil {
263+
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
264+
f.commentPos = bgLen
265+
}
262266
}
267+
text := s(f.indent) + bcl(f.scenario.Keyword+": ", white) + f.scenario.Name
268+
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
269+
fmt.Println("\n" + text)
270+
f.scenarioKeyword = true
263271
}
264-
text := s(f.indent) + bcl(f.scenario.Keyword+": ", white) + f.scenario.Name
265-
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
266-
fmt.Println("\n" + text)
267-
f.steps--
268-
// all subsequent scenario steps
269-
case f.scenario != nil:
270272
f.steps--
271273
// first step of outline scenario, print header and calculate comment position
272-
case f.outline != nil && f.steps == len(f.outline.Steps):
273-
f.commentPos = f.longestStep(f.outline.Steps, f.length(f.outline))
274-
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
275-
f.commentPos = bgLen
276-
}
277-
text := s(f.indent) + bcl(f.outline.Keyword+": ", white) + f.outline.Name
278-
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
279-
fmt.Println("\n" + text)
280-
f.outlineSteps = append(f.outlineSteps, res)
281-
f.steps--
282-
if len(f.outlineSteps) == len(f.outline.Steps) {
283-
// an outline example steps has went through
284-
f.printOutlineExample(f.outline)
285-
f.outlineSteps = []*stepResult{}
286-
f.outlineNumExamples--
287-
}
288-
return
289-
// all subsequent outline steps
290274
case f.outline != nil:
291275
f.outlineSteps = append(f.outlineSteps, res)
292276
f.steps--
293-
if len(f.outlineSteps) == len(f.outline.Steps) {
277+
278+
// print scenario keyword and value if first example
279+
if !f.scenarioKeyword {
280+
f.commentPos = f.longestStep(f.outline.Steps, f.length(f.outline))
281+
if f.feature.Background != nil {
282+
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
283+
f.commentPos = bgLen
284+
}
285+
}
286+
text := s(f.indent) + bcl(f.outline.Keyword+": ", white) + f.outline.Name
287+
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
288+
fmt.Println("\n" + text)
289+
f.scenarioKeyword = true
290+
}
291+
if len(f.outlineSteps) == len(f.outline.Steps)+f.bgSteps {
294292
// an outline example steps has went through
295293
f.printOutlineExample(f.outline)
296-
f.outlineSteps = []*stepResult{}
297294
f.outlineNumExamples--
298295
}
299296
return

godog.go

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

4444
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
45-
const Version = "v0.5.0"
45+
const Version = "v0.5.3"

0 commit comments

Comments
 (0)