diff --git a/examples/api/version.feature b/examples/api/version.feature index 16c730b..a44d272 100644 --- a/examples/api/version.feature +++ b/examples/api/version.feature @@ -20,6 +20,6 @@ Feature: get version And the response should match json: """ { - "version": "v0.5.0" + "version": "v0.5.3" } """ diff --git a/fmt.go b/fmt.go index 4e35933..172d10f 100644 --- a/fmt.go +++ b/fmt.go @@ -145,12 +145,10 @@ type basefmt struct { func (f *basefmt) Node(n interface{}) { switch t := n.(type) { - case *gherkin.ScenarioOutline: + case *gherkin.TableRow: f.owner = t case *gherkin.Scenario: f.owner = t - case *gherkin.Background: - f.owner = t } } diff --git a/fmt_pretty.go b/fmt_pretty.go index b17a75e..8889ce8 100644 --- a/fmt_pretty.go +++ b/fmt_pretty.go @@ -36,6 +36,9 @@ type pretty struct { steps int commentPos int + // whether scenario or scenario outline keyword was printed + scenarioKeyword bool + // outline outlineSteps []*stepResult outlineNumExample int @@ -75,12 +78,16 @@ func (f *pretty) Node(node interface{}) { case *gherkin.Scenario: f.scenario = t f.outline = nil - f.steps = len(t.Steps) + f.steps = len(t.Steps) + f.bgSteps + f.scenarioKeyword = false case *gherkin.ScenarioOutline: f.outline = t f.scenario = nil - f.steps = len(t.Steps) f.outlineNumExample = -1 + f.scenarioKeyword = false + case *gherkin.TableRow: + f.steps = len(f.outline.Steps) + f.bgSteps + f.outlineSteps = []*stepResult{} } } @@ -237,8 +244,6 @@ func (f *pretty) printStep(step *gherkin.Step, def *StepDef, c color) { } func (f *pretty) printStepKind(res *stepResult) { - _, isBgStep := res.owner.(*gherkin.Background) - // if has not printed background yet switch { // first background step @@ -249,51 +254,43 @@ func (f *pretty) printStepKind(res *stepResult) { // subsequent background steps case f.bgSteps > 0: f.bgSteps-- - // a background step for another scenario, but all bg steps are - // already printed. so just skip it - case isBgStep: - return // first step of scenario, print header and calculate comment position - case f.scenario != nil && f.steps == len(f.scenario.Steps): - f.commentPos = f.longestStep(f.scenario.Steps, f.length(f.scenario)) - if f.feature.Background != nil { - if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos { - f.commentPos = bgLen - } - } - text := s(f.indent) + bcl(f.scenario.Keyword+": ", white) + f.scenario.Name - text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location) - fmt.Println("\n" + text) - f.steps-- - // all subsequent scenario steps case f.scenario != nil: + // print scenario keyword and value if first example + if !f.scenarioKeyword { + f.commentPos = f.longestStep(f.scenario.Steps, f.length(f.scenario)) + if f.feature.Background != nil { + if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos { + f.commentPos = bgLen + } + } + text := s(f.indent) + bcl(f.scenario.Keyword+": ", white) + f.scenario.Name + text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location) + fmt.Println("\n" + text) + f.scenarioKeyword = true + } f.steps-- // first step of outline scenario, print header and calculate comment position - case f.outline != nil && f.steps == len(f.outline.Steps): - f.commentPos = f.longestStep(f.outline.Steps, f.length(f.outline)) - if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos { - f.commentPos = bgLen - } - text := s(f.indent) + bcl(f.outline.Keyword+": ", white) + f.outline.Name - text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location) - fmt.Println("\n" + text) - f.outlineSteps = append(f.outlineSteps, res) - f.steps-- - if len(f.outlineSteps) == len(f.outline.Steps) { - // an outline example steps has went through - f.printOutlineExample(f.outline) - f.outlineSteps = []*stepResult{} - f.outlineNumExamples-- - } - return - // all subsequent outline steps case f.outline != nil: f.outlineSteps = append(f.outlineSteps, res) f.steps-- - if len(f.outlineSteps) == len(f.outline.Steps) { + + // print scenario keyword and value if first example + if !f.scenarioKeyword { + f.commentPos = f.longestStep(f.outline.Steps, f.length(f.outline)) + if f.feature.Background != nil { + if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos { + f.commentPos = bgLen + } + } + text := s(f.indent) + bcl(f.outline.Keyword+": ", white) + f.outline.Name + text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location) + fmt.Println("\n" + text) + f.scenarioKeyword = true + } + if len(f.outlineSteps) == len(f.outline.Steps)+f.bgSteps { // an outline example steps has went through f.printOutlineExample(f.outline) - f.outlineSteps = []*stepResult{} f.outlineNumExamples-- } return diff --git a/godog.go b/godog.go index 6459886..0b5a6d3 100644 --- a/godog.go +++ b/godog.go @@ -42,4 +42,4 @@ Godog was inspired by Behat and Cucumber the above description is taken from it' package godog // Version of package - based on Semantic Versioning 2.0.0 http://semver.org/ -const Version = "v0.5.0" +const Version = "v0.5.3"