Skip to content

Commit

Permalink
Add details to "step is undefined" error
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Dec 10, 2024
1 parent da4633a commit 0e3f7af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
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

0 comments on commit 0e3f7af

Please sign in to comment.