From fb26a4d567caa34a22798298803fb7a0ad3f067d Mon Sep 17 00:00:00 2001 From: gedi Date: Wed, 7 Sep 2016 08:06:03 +0300 Subject: [PATCH] fixed test case finished event determination --- fmt.go | 23 +++++++++++++++++++++++ fmt_events.go | 19 ++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/fmt.go b/fmt.go index d18cee3..88b471e 100644 --- a/fmt.go +++ b/fmt.go @@ -414,3 +414,26 @@ func (f *basefmt) snippets() string { } return buf.String() } + +func (f *basefmt) isLastStep(s *gherkin.Step) bool { + ft := f.features[len(f.features)-1] + + for _, def := range ft.ScenarioDefinitions { + if outline, ok := def.(*gherkin.ScenarioOutline); ok { + for n, step := range outline.Steps { + if step.Location.Line == s.Location.Line { + return n == len(outline.Steps)-1 + } + } + } + + if scenario, ok := def.(*gherkin.Scenario); ok { + for n, step := range scenario.Steps { + if step.Location.Line == s.Location.Line { + return n == len(scenario.Steps)-1 + } + } + } + } + return false +} diff --git a/fmt_events.go b/fmt_events.go index 7473e3c..af28c86 100644 --- a/fmt_events.go +++ b/fmt_events.go @@ -112,14 +112,22 @@ func (f *events) Summary() { status = pending } } + + snips := f.snippets() + if len(snips) > 0 { + snips = "You can implement step definitions for undefined steps with these snippets:\n" + snips + } + f.event(&struct { Event string `json:"event"` Status string `json:"status"` Timestamp int64 `json:"timestamp"` + Snippets string `json:"snippets"` }{ "TestRunFinished", status.String(), time.Now().UnixNano() / nanoSec, + snips, }) } @@ -146,15 +154,12 @@ func (f *events) step(res *stepResult) { var finished bool var line int switch t := f.owner.(type) { - case *gherkin.ScenarioOutline: - if t.Steps[len(t.Steps)-1].Location.Line == res.step.Location.Line { - finished = true - last := t.Examples[len(t.Examples)-1] - line = last.TableBody[len(last.TableBody)-1].Location.Line - } + case *gherkin.TableRow: + line = t.Location.Line + finished = f.isLastStep(res.step) case *gherkin.Scenario: line = t.Location.Line - finished = t.Steps[len(t.Steps)-1].Location.Line == res.step.Location.Line + finished = f.isLastStep(res.step) } if finished {