Fixed an issue when executing empty Features or Scenarios

Этот коммит содержится в:
Fredrik Lönnblad 2020-01-20 14:24:18 -03:00
родитель f988d266ed
коммит 6f6ffc597a
2 изменённых файлов: 27 добавлений и 2 удалений

5
fmt.go
Просмотреть файл

@ -242,7 +242,8 @@ func (f *basefmt) Node(n interface{}) {
case *gherkin.Scenario:
f.owner = t
feature := f.features[len(f.features)-1]
feature.Scenarios = append(feature.Scenarios, &scenario{Name: t.Name})
feature.time = timeNowFunc()
feature.Scenarios = append(feature.Scenarios, &scenario{Name: t.Name, time: feature.time})
case *gherkin.ScenarioOutline:
feature := f.features[len(f.features)-1]
feature.Scenarios = append(feature.Scenarios, &scenario{OutlineName: t.Name})
@ -252,7 +253,7 @@ func (f *basefmt) Node(n interface{}) {
feature := f.features[len(f.features)-1]
lastExample := feature.Scenarios[len(feature.Scenarios)-1]
newExample := scenario{OutlineName: lastExample.OutlineName, ExampleNo: lastExample.ExampleNo + 1}
newExample := scenario{OutlineName: lastExample.OutlineName, ExampleNo: lastExample.ExampleNo + 1, time: timeNowFunc()}
newExample.Name = fmt.Sprintf("%s #%d", newExample.OutlineName, newExample.ExampleNo)
const firstExample = 1

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

@ -26,16 +26,28 @@ type feature struct {
Scenarios []*scenario
time time.Time
Content []byte `json:"-"`
Path string `json:"path"`
order int
}
func (f feature) startedAt() time.Time {
<<<<<<< Updated upstream
return f.Scenarios[0].startedAt()
}
func (f feature) finishedAt() time.Time {
=======
return f.time
}
func (f feature) finishedAt() time.Time {
if len(f.Scenarios) == 0 {
return f.startedAt()
}
>>>>>>> Stashed changes
return f.Scenarios[len(f.Scenarios)-1].finishedAt()
}
@ -48,14 +60,26 @@ type scenario struct {
Name string
OutlineName string
ExampleNo int
time time.Time
Steps []*stepResult
}
func (s scenario) startedAt() time.Time {
<<<<<<< Updated upstream
return s.Steps[0].time
}
func (s scenario) finishedAt() time.Time {
=======
return s.time
}
func (s scenario) finishedAt() time.Time {
if len(s.Steps) == 0 {
return s.startedAt()
}
>>>>>>> Stashed changes
return s.Steps[len(s.Steps)-1].time
}