Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add details to "step is undefined" error #669

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions internal/formatters/fmt_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`)},
)
Expand Down Expand Up @@ -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

Expand All @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions suite_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: <nil>, status: skipped
<< After scenario "test", error: <nil>
Expand All @@ -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: <nil>, status: skipped
<<<< After suite`,
Expand All @@ -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`,
},
{
Expand Down
Loading