some tests with background steps

Этот коммит содержится в:
gedi 2018-11-15 15:50:23 +02:00
родитель 2ef5a29c36
коммит bfec1e9b48
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 56604CDCCC201556
7 изменённых файлов: 105 добавлений и 16 удалений

Просмотреть файл

@ -58,7 +58,7 @@ func (f *pretty) Feature(ft *gherkin.Feature, p string, c []byte) {
fmt.Fprintln(f.out, "")
}
f.features = append(f.features, &feature{Path: p, Feature: ft})
fmt.Fprintln(f.out, whiteb(ft.Keyword+":")+" "+ft.Name)
fmt.Fprintln(f.out, keywordAndName(ft.Keyword, ft.Name))
if strings.TrimSpace(ft.Description) != "" {
for _, line := range strings.Split(ft.Description, "\n") {
fmt.Fprintln(f.out, s(f.indent)+strings.TrimSpace(line))
@ -106,12 +106,21 @@ func (f *pretty) Node(node interface{}) {
}
}
func keywordAndName(keyword, name string) string {
title := whiteb(keyword + ":")
if len(name) > 0 {
title += " " + name
}
return title
}
func (f *pretty) printUndefinedScenario(sc interface{}) {
if f.bgSteps > 0 {
f.commentPos = f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background))
fmt.Fprintln(f.out, "\n"+s(f.indent)+whiteb(f.feature.Background.Keyword+": "+f.feature.Background.Name))
bg := f.feature.Background
f.commentPos = f.longestStep(bg.Steps, f.length(bg))
fmt.Fprintln(f.out, "\n"+s(f.indent)+keywordAndName(bg.Keyword, bg.Name))
for _, step := range f.feature.Background.Steps {
for _, step := range bg.Steps {
f.bgSteps--
f.printStep(step, nil, colors.Cyan)
}
@ -120,12 +129,12 @@ func (f *pretty) printUndefinedScenario(sc interface{}) {
switch t := sc.(type) {
case *gherkin.Scenario:
f.commentPos = f.longestStep(t.Steps, f.length(sc))
text := s(f.indent) + whiteb(t.Keyword+":") + " " + t.Name
text := s(f.indent) + keywordAndName(t.Keyword, t.Name)
text += s(f.commentPos-f.length(t)+1) + f.line(t.Location)
fmt.Fprintln(f.out, "\n"+text)
case *gherkin.ScenarioOutline:
f.commentPos = f.longestStep(t.Steps, f.length(sc))
text := s(f.indent) + whiteb(t.Keyword+":") + " " + t.Name
text := s(f.indent) + keywordAndName(t.Keyword, t.Name)
text += s(f.commentPos-f.length(t)+1) + f.line(t.Location)
fmt.Fprintln(f.out, "\n"+text)
@ -254,7 +263,7 @@ func (f *pretty) printExampleHeader(example *gherkin.Examples, max []int) {
cells := make([]string, len(example.TableHeader.Cells))
// an example table header
fmt.Fprintln(f.out, "")
fmt.Fprintln(f.out, s(f.indent*2)+whiteb(example.Keyword+":")+" "+example.Name)
fmt.Fprintln(f.out, s(f.indent*2)+keywordAndName(example.Keyword, example.Name))
for i, cell := range example.TableHeader.Cells {
val := cyan(cell.Value)
@ -313,13 +322,14 @@ func (f *pretty) printStepKind(res *stepResult) {
f.outlineSteps = append(f.outlineSteps, res)
}
var bgStep bool
bg := f.feature.Background
// if has not printed background yet
switch {
// first background step
case f.bgSteps > 0 && f.bgSteps == len(f.feature.Background.Steps):
f.commentPos = f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background))
fmt.Fprintln(f.out, "\n"+s(f.indent)+whiteb(f.feature.Background.Keyword+": "+f.feature.Background.Name))
case f.bgSteps > 0 && f.bgSteps == len(bg.Steps):
f.commentPos = f.longestStep(bg.Steps, f.length(bg))
fmt.Fprintln(f.out, "\n"+s(f.indent)+keywordAndName(bg.Keyword, bg.Name))
f.bgSteps--
bgStep = true
// subsequent background steps
@ -331,12 +341,12 @@ func (f *pretty) printStepKind(res *stepResult) {
// 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 {
if bg != nil {
if bgLen := f.longestStep(bg.Steps, f.length(bg)); bgLen > f.commentPos {
f.commentPos = bgLen
}
}
text := s(f.indent) + whiteb(f.scenario.Keyword+":") + " " + f.scenario.Name
text := s(f.indent) + keywordAndName(f.scenario.Keyword, f.scenario.Name)
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
fmt.Fprintln(f.out, "\n"+text)
f.scenarioKeyword = true
@ -346,12 +356,12 @@ func (f *pretty) printStepKind(res *stepResult) {
// 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 {
if bg != nil {
if bgLen := f.longestStep(bg.Steps, f.length(bg)); bgLen > f.commentPos {
f.commentPos = bgLen
}
}
text := s(f.indent) + whiteb(f.outline.Keyword+": ") + f.outline.Name
text := s(f.indent) + keywordAndName(f.outline.Keyword, f.outline.Name)
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
fmt.Fprintln(f.out, "\n"+text)
f.scenarioKeyword = true

Просмотреть файл

@ -0,0 +1,9 @@
Feature: single scenario with background
Background: named
Given passing step
And passing step
Scenario: scenario
When passing step
Then passing step

Просмотреть файл

@ -0,0 +1,6 @@
Feature: empty feature
Background:
Given passing step
Scenario: without steps

Просмотреть файл

@ -0,0 +1,12 @@
Feature: two scenarios with background fail
Background:
Given passing step
And failing step
Scenario: one
When passing step
Then passing step
Scenario: two
Then passing step

Просмотреть файл

@ -0,0 +1,13 @@
<bold-white>Feature:</bold-white> single scenario with background
<bold-white>Background:</bold-white> named
<green>Given</green> <green>passing step</green> <black># formatters_print_test.go:64 -> passingStepDef</black>
<green>And</green> <green>passing step</green> <black># formatters_print_test.go:64 -> passingStepDef</black>
<bold-white>Scenario:</bold-white> scenario <black># formatter-tests/features/scenario_with_background.feature:7</black>
<green>When</green> <green>passing step</green> <black># formatters_print_test.go:64 -> passingStepDef</black>
<green>Then</green> <green>passing step</green> <black># formatters_print_test.go:64 -> passingStepDef</black>
1 scenarios (<green>1 passed</green>)
4 steps (<green>4 passed</green>)
0s

Просмотреть файл

@ -0,0 +1,10 @@
<bold-white>Feature:</bold-white> empty feature
<bold-white>Background:</bold-white>
<cyan>Given</cyan> <cyan>passing step</cyan>
<bold-white>Scenario:</bold-white> without steps <black># formatter-tests/features/scenario_without_steps_with_background.feature:6</black>
1 scenarios (<yellow>1 undefined</yellow>)
No steps
0s

Просмотреть файл

@ -0,0 +1,29 @@
<bold-white>Feature:</bold-white> two scenarios with background fail
<bold-white>Background:</bold-white>
<green>Given</green> <green>passing step</green> <black># formatters_print_test.go:64 -> passingStepDef</black>
<red>And</red> <red>failing step</red> <black># formatters_print_test.go:80 -> failingStepDef</black>
<bold-red>step failed</bold-red>
<bold-white>Scenario:</bold-white> one <black># formatter-tests/features/two_scenarios_with_background_fail.feature:7</black>
<cyan>When</cyan> <cyan>passing step</cyan> <black># formatters_print_test.go:64 -> passingStepDef</black>
<cyan>Then</cyan> <cyan>passing step</cyan> <black># formatters_print_test.go:64 -> passingStepDef</black>
<bold-white>Scenario:</bold-white> two <black># formatter-tests/features/two_scenarios_with_background_fail.feature:11</black>
<bold-red>step failed</bold-red>
<cyan>Then</cyan> <cyan>passing step</cyan> <black># formatters_print_test.go:64 -> passingStepDef</black>
--- <red>Failed steps:</red>
<red>Scenario: one</red><black> # formatter-tests/features/two_scenarios_with_background_fail.feature:7</black>
<red>And failing step</red><black> # formatter-tests/features/two_scenarios_with_background_fail.feature:5</black>
<red>Error: </red><bold-red>step failed</bold-red>
<red>Scenario: two</red><black> # formatter-tests/features/two_scenarios_with_background_fail.feature:11</black>
<red>And failing step</red><black> # formatter-tests/features/two_scenarios_with_background_fail.feature:5</black>
<red>Error: </red><bold-red>step failed</bold-red>
2 scenarios (<red>2 failed</red>)
7 steps (<green>2 passed</green>, <red>2 failed</red>, <cyan>3 skipped</cyan>)
0s