From 8242348e2ab88c58c4db7cbcc6aff719c0805d9e Mon Sep 17 00:00:00 2001 From: Clinton Bush Date: Thu, 14 Mar 2019 22:47:48 -0400 Subject: [PATCH] Added datatables to cucumber json results files. --- .gitignore | 3 +++ fmt_cucumber.go | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 7037299..b706642 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /cmd/godog/godog /example/example +**/vendor/* +Gopkg.lock +Gopkg.toml diff --git a/fmt_cucumber.go b/fmt_cucumber.go index cbfe30d..f67b883 100644 --- a/fmt_cucumber.go +++ b/fmt_cucumber.go @@ -71,12 +71,17 @@ type cukeMatch struct { } type cukeStep struct { - Keyword string `json:"keyword"` - Name string `json:"name"` - Line int `json:"line"` - Docstring *cukeDocstring `json:"doc_string,omitempty"` - Match cukeMatch `json:"match"` - Result cukeResult `json:"result"` + Keyword string `json:"keyword"` + Name string `json:"name"` + Line int `json:"line"` + Docstring *cukeDocstring `json:"doc_string,omitempty"` + Match cukeMatch `json:"match"` + Result cukeResult `json:"result"` + DataTable []*cukeDataTableRow `json:"rows,omitempty"` +} + +type cukeDataTableRow struct { + Cells []string `json:"cells"` } type cukeElement struct { @@ -285,6 +290,19 @@ func (f *cukefmt) Defined(step *gherkin.Step, def *StepDef) { f.curStep.Docstring.Value = step.Argument.(*gherkin.DocString).Content } + if _, ok := step.Argument.(*gherkin.DataTable); ok { + dataTable := step.Argument.(*gherkin.DataTable) + + f.curStep.DataTable = make([]*cukeDataTableRow, len(dataTable.Rows)) + for i, row := range dataTable.Rows { + cells := make([]string, len(row.Cells)) + for j, cell := range row.Cells { + cells[j] = cell.Value + } + f.curStep.DataTable[i] = &cukeDataTableRow{Cells: cells} + } + } + if def != nil { f.curStep.Match.Location = strings.Split(def.definitionID(), " ")[0] }