Skip to content

Commit

Permalink
be compatible with gherkin library changes
Browse files Browse the repository at this point in the history
the downside is that if outline examples are empty
it won't be pretty printed as node. But that does not make
much difference anyway
  • Loading branch information
l3pp4rd committed Mar 4, 2016
1 parent 34899b4 commit e9c3d69
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
4 changes: 3 additions & 1 deletion fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ func (f *basefmt) Summary() {
total++
case *gherkin.ScenarioOutline:
for _, ex := range t.Examples {
total += len(ex.TableBody)
if examples, hasExamples := examples(ex); hasExamples {
total += len(examples.TableBody)
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion fmt_pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ func (f *pretty) printOutlineExample(outline *gherkin.ScenarioOutline) {
var msg string
clr := green

example := outline.Examples[f.outlineNumExample]
ex := outline.Examples[f.outlineNumExample]
example, hasExamples := examples(ex)
if !hasExamples {
// do not print empty examples
return
}

firstExample := f.outlineNumExamples == len(example.TableBody)
printSteps := firstExample && f.outlineNumExample == 0

Expand Down
10 changes: 10 additions & 0 deletions gherkin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package godog

import "gopkg.in/cucumber/gherkin-go.v3"

// examples is a helper func to cast gherkin.Examples
// or gherkin.BaseExamples if its empty
func examples(ex interface{}) (*gherkin.Examples, bool) {
t, ok := ex.(*gherkin.Examples)
return t, ok
}
11 changes: 9 additions & 2 deletions suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,16 @@ func (s *Suite) skipSteps(steps []*gherkin.Step) {
func (s *Suite) runOutline(outline *gherkin.ScenarioOutline, b *gherkin.Background) (failErr error) {
s.fmt.Node(outline)

for _, example := range outline.Examples {
s.fmt.Node(example)
for _, ex := range outline.Examples {
example, hasExamples := examples(ex)
if !hasExamples {
// @TODO: may need to print empty example node, but
// for backward compatibility, cannot cast to *gherkin.ExamplesBase
// at the moment
continue
}

s.fmt.Node(example)
placeholders := example.TableHeader.Cells
groups := example.TableBody

Expand Down

0 comments on commit e9c3d69

Please sign in to comment.