diff --git a/examples/api/version.feature b/examples/api/version.feature index 3664fa2..6a3581a 100644 --- a/examples/api/version.feature +++ b/examples/api/version.feature @@ -20,6 +20,6 @@ Feature: get version And the response should match json: """ { - "version": "v0.7.0" + "version": "v0.7.1" } """ diff --git a/features/run.feature b/features/run.feature index b8f033c..9046d5a 100644 --- a/features/run.feature +++ b/features/run.feature @@ -190,3 +190,75 @@ Feature: run features """ I should have 1 scenario registered """ + + Scenario: should fail suite if undefined steps follow after the failure + Given a feature "failed.feature" file: + """ + Feature: failed feature + + Scenario: parse a scenario + Given a failing step + When an undefined step + Then another undefined step + """ + When I run feature suite + Then the following step should be failed: + """ + a failing step + """ + And the following steps should be undefined: + """ + an undefined step + another undefined step + """ + And the suite should have failed + + Scenario: should fail suite and skip pending step after failed step + Given a feature "failed.feature" file: + """ + Feature: failed feature + + Scenario: parse a scenario + Given a failing step + When pending step + Then another undefined step + """ + When I run feature suite + Then the following step should be failed: + """ + a failing step + """ + And the following steps should be skipped: + """ + pending step + """ + And the following steps should be undefined: + """ + another undefined step + """ + And the suite should have failed + + Scenario: should fail suite and skip next step after failed step + Given a feature "failed.feature" file: + """ + Feature: failed feature + + Scenario: parse a scenario + Given a failing step + When a failing step + Then another undefined step + """ + When I run feature suite + Then the following step should be failed: + """ + a failing step + """ + And the following steps should be skipped: + """ + a failing step + """ + And the following steps should be undefined: + """ + another undefined step + """ + And the suite should have failed diff --git a/godog.go b/godog.go index a8a2984..5e080fc 100644 --- a/godog.go +++ b/godog.go @@ -39,4 +39,4 @@ Godog was inspired by Behat and Cucumber the above description is taken from it' package godog // Version of package - based on Semantic Versioning 2.0.0 http://semver.org/ -const Version = "v0.7.0" +const Version = "v0.7.1" diff --git a/suite.go b/suite.go index 74ed3f6..b256277 100644 --- a/suite.go +++ b/suite.go @@ -335,13 +335,15 @@ func (s *Suite) matchStepText(text string) *StepDef { return nil } -func (s *Suite) runSteps(steps []*gherkin.Step, prevErr error) (err error) { - err = prevErr +func (s *Suite) runSteps(steps []*gherkin.Step) (err error) { for _, step := range steps { stepErr := s.runStep(step, err) switch stepErr { case ErrUndefined: - err = stepErr + // do not overwrite failed error + if err == ErrUndefined || err == nil { + err = stepErr + } case ErrPending: err = stepErr case nil: @@ -397,12 +399,11 @@ func (s *Suite) runOutline(outline *gherkin.ScenarioOutline, b *gherkin.Backgrou // run example table row s.fmt.Node(group) - // run background - var err error if b != nil { - err = s.runSteps(b.Steps, err) + steps = append(b.Steps, steps...) } - err = s.runSteps(steps, err) + + err := s.runSteps(steps) for _, f := range s.afterScenarioHandlers { f(outline, err) @@ -464,12 +465,13 @@ func (s *Suite) runScenario(scenario *gherkin.Scenario, b *gherkin.Background) ( s.fmt.Node(scenario) // background + steps := scenario.Steps if b != nil { - err = s.runSteps(b.Steps, err) + steps = append(b.Steps, steps...) } // scenario - err = s.runSteps(scenario.Steps, err) + err = s.runSteps(steps) // run after scenario handlers for _, f := range s.afterScenarioHandlers {