From 0e3f7af7c29c7dc9dc407e35cfd2aa15a3ab58df Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Tue, 10 Dec 2024 15:15:37 +0100 Subject: [PATCH 1/2] Add details to "step is undefined" error --- internal/formatters/fmt_base_test.go | 10 +++++----- suite.go | 6 +++--- suite_context_test.go | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/formatters/fmt_base_test.go b/internal/formatters/fmt_base_test.go index ef6e8d2c..f14efcf8 100644 --- a/internal/formatters/fmt_base_test.go +++ b/internal/formatters/fmt_base_test.go @@ -42,7 +42,7 @@ And step failed f2s3:4 Scenario: f2s4 When step passed f2s4:1 -Then step is undefined f2s4:2 +Then something unknown happens f2s4:2 And step passed f2s4:3 `)}, ) @@ -116,8 +116,8 @@ scenario "f2s3" passed step invoked: "f2s4:1", passed step "step passed f2s4:1" finished with status passed -.Ustep "step is undefined f2s4:2" finished with status undefined -scenario "f2s4" ended with error "step is undefined" +.Ustep "something unknown happens f2s4:2" finished with status undefined +scenario "f2s4" ended with error "step is undefined: something unknown happens f2s4:2" -step "step passed f2s4:3" finished with status skipped 13 @@ -139,12 +139,12 @@ scenario "f2s4" ended with error "step is undefined" You can implement step definitions for undefined steps with these snippets: -func stepIsUndefinedFS(arg1, arg2, arg3 int) error { +func somethingUnknownHappensFS(arg1, arg2, arg3 int) error { return godog.ErrPending } func InitializeScenario(ctx *godog.ScenarioContext) { - ctx.Step(`+"`"+`^step is undefined f(\d+)s(\d+):(\d+)$`+"`"+`, stepIsUndefinedFS) + ctx.Step(`+"`"+`^something unknown happens f(\d+)s(\d+):(\d+)$`+"`"+`, somethingUnknownHappensFS) } `, out.String()) diff --git a/suite.go b/suite.go index 9a387299..b3a87a0b 100644 --- a/suite.go +++ b/suite.go @@ -270,7 +270,7 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena s.storage.MustInsertPickleStepResult(sr) s.fmt.Undefined(pickle, step, match.GetInternalStepDefinition()) - return ctx, ErrUndefined + return ctx, fmt.Errorf("%w: %s", ErrUndefined, step.Text) } if scenarioErr != nil { @@ -461,7 +461,7 @@ func (s *suite) maybeSubSteps(ctx context.Context, result interface{}) (context. } if def == nil { - return ctx, ErrUndefined + return ctx, fmt.Errorf("%w: %s", ErrUndefined, text) } else { ctx, err = s.runSubStep(ctx, text, def) if err != nil { @@ -609,7 +609,7 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) { s.storage.MustInsertPickleResult(pr) s.fmt.Pickle(pickle) - return ErrUndefined + return fmt.Errorf("%w: no steps in scenario", ErrUndefined) } // Before scenario hooks are called in context of first evaluated step diff --git a/suite_context_test.go b/suite_context_test.go index 9b042d82..675389f8 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -1008,13 +1008,13 @@ func TestTestSuite_Run(t *testing.T) { { name: "undefined_then_pass_no_strict_doesnt_fail_scenario", afterStepCnt: 2, beforeStepCnt: 2, noStrict: true, suitePasses: true, body: ` - When step is undefined + When something unknown happens Then step passes`, log: ` >>>> Before suite >> Before scenario "test" - Before step "step is undefined" - After step "step is undefined", error: step is undefined, status: undefined + Before step "something unknown happens" + After step "something unknown happens", error: step is undefined: something unknown happens, status: undefined Before step "step passes" After step "step passes", error: , status: skipped << After scenario "test", error: @@ -1023,14 +1023,14 @@ func TestTestSuite_Run(t *testing.T) { { name: "undefined_then_pass_fails_scenario", afterStepCnt: 2, beforeStepCnt: 2, body: ` - When step is undefined + When something unknown happens Then step passes`, log: ` >>>> Before suite >> Before scenario "test" - Before step "step is undefined" - After step "step is undefined", error: step is undefined, status: undefined - << After scenario "test", error: step is undefined + Before step "something unknown happens" + After step "something unknown happens", error: step is undefined: something unknown happens, status: undefined + << After scenario "test", error: step is undefined: something unknown happens Before step "step passes" After step "step passes", error: , status: skipped <<<< After suite`, @@ -1039,15 +1039,15 @@ func TestTestSuite_Run(t *testing.T) { name: "fail_then_undefined_fails_scenario", afterStepCnt: 2, beforeStepCnt: 2, body: ` When step fails - Then step is undefined`, + Then something unknown happens`, log: ` >>>> Before suite >> Before scenario "test" Before step "step fails" After step "step fails", error: oops, status: failed << After scenario "test", error: oops - Before step "step is undefined" - After step "step is undefined", error: step is undefined, status: undefined + Before step "something unknown happens" + After step "something unknown happens", error: step is undefined: something unknown happens, status: undefined <<<< After suite`, }, { From 36f4bf5596b17b9c9c6992c6f8655b7ffb1a25f0 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Tue, 10 Dec 2024 15:32:02 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d6c7e1d..6be6f8da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt ## Unreleased +### Added +- Step text is added to "step is undefined" error - ([669](https://github.com/cucumber/godog/pull/669) - [vearutop](https://github.com/vearutop)) + +### Fixed - fix(formatter): On concurrent execution, execute formatter at end of Scenario - ([645](https://github.com/cucumber/godog/pull/645) - [tigh-latte](https://github.com/tigh-latte)) ## [v0.15.0]