Skip to content

Commit e55eab6

Browse files
authored
Add details to "step is undefined" error (#669)
* Add details to "step is undefined" error * Update changelog
1 parent da4633a commit e55eab6

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
88

99
## Unreleased
1010

11+
### Added
12+
- Step text is added to "step is undefined" error - ([669](https://github.com/cucumber/godog/pull/669) - [vearutop](https://github.com/vearutop))
13+
14+
### Fixed
1115
- 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))
1216

1317
## [v0.15.0]

internal/formatters/fmt_base_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ And step failed f2s3:4
4242
4343
Scenario: f2s4
4444
When step passed f2s4:1
45-
Then step is undefined f2s4:2
45+
Then something unknown happens f2s4:2
4646
And step passed f2s4:3
4747
`)},
4848
)
@@ -116,8 +116,8 @@ scenario "f2s3" passed
116116
117117
step invoked: "f2s4:1", passed
118118
step "step passed f2s4:1" finished with status passed
119-
.Ustep "step is undefined f2s4:2" finished with status undefined
120-
scenario "f2s4" ended with error "step is undefined"
119+
.Ustep "something unknown happens f2s4:2" finished with status undefined
120+
scenario "f2s4" ended with error "step is undefined: something unknown happens f2s4:2"
121121
-step "step passed f2s4:3" finished with status skipped
122122
13
123123
@@ -139,12 +139,12 @@ scenario "f2s4" ended with error "step is undefined"
139139
140140
You can implement step definitions for undefined steps with these snippets:
141141
142-
func stepIsUndefinedFS(arg1, arg2, arg3 int) error {
142+
func somethingUnknownHappensFS(arg1, arg2, arg3 int) error {
143143
return godog.ErrPending
144144
}
145145
146146
func InitializeScenario(ctx *godog.ScenarioContext) {
147-
ctx.Step(`+"`"+`^step is undefined f(\d+)s(\d+):(\d+)$`+"`"+`, stepIsUndefinedFS)
147+
ctx.Step(`+"`"+`^something unknown happens f(\d+)s(\d+):(\d+)$`+"`"+`, somethingUnknownHappensFS)
148148
}
149149
150150
`, out.String())

suite.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena
270270
s.storage.MustInsertPickleStepResult(sr)
271271

272272
s.fmt.Undefined(pickle, step, match.GetInternalStepDefinition())
273-
return ctx, ErrUndefined
273+
return ctx, fmt.Errorf("%w: %s", ErrUndefined, step.Text)
274274
}
275275

276276
if scenarioErr != nil {
@@ -461,7 +461,7 @@ func (s *suite) maybeSubSteps(ctx context.Context, result interface{}) (context.
461461
}
462462

463463
if def == nil {
464-
return ctx, ErrUndefined
464+
return ctx, fmt.Errorf("%w: %s", ErrUndefined, text)
465465
} else {
466466
ctx, err = s.runSubStep(ctx, text, def)
467467
if err != nil {
@@ -609,7 +609,7 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) {
609609
s.storage.MustInsertPickleResult(pr)
610610

611611
s.fmt.Pickle(pickle)
612-
return ErrUndefined
612+
return fmt.Errorf("%w: no steps in scenario", ErrUndefined)
613613
}
614614

615615
// Before scenario hooks are called in context of first evaluated step

suite_context_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,13 +1008,13 @@ func TestTestSuite_Run(t *testing.T) {
10081008
{
10091009
name: "undefined_then_pass_no_strict_doesnt_fail_scenario", afterStepCnt: 2, beforeStepCnt: 2, noStrict: true, suitePasses: true,
10101010
body: `
1011-
When step is undefined
1011+
When something unknown happens
10121012
Then step passes`,
10131013
log: `
10141014
>>>> Before suite
10151015
>> Before scenario "test"
1016-
Before step "step is undefined"
1017-
After step "step is undefined", error: step is undefined, status: undefined
1016+
Before step "something unknown happens"
1017+
After step "something unknown happens", error: step is undefined: something unknown happens, status: undefined
10181018
Before step "step passes"
10191019
After step "step passes", error: <nil>, status: skipped
10201020
<< After scenario "test", error: <nil>
@@ -1023,14 +1023,14 @@ func TestTestSuite_Run(t *testing.T) {
10231023
{
10241024
name: "undefined_then_pass_fails_scenario", afterStepCnt: 2, beforeStepCnt: 2,
10251025
body: `
1026-
When step is undefined
1026+
When something unknown happens
10271027
Then step passes`,
10281028
log: `
10291029
>>>> Before suite
10301030
>> Before scenario "test"
1031-
Before step "step is undefined"
1032-
After step "step is undefined", error: step is undefined, status: undefined
1033-
<< After scenario "test", error: step is undefined
1031+
Before step "something unknown happens"
1032+
After step "something unknown happens", error: step is undefined: something unknown happens, status: undefined
1033+
<< After scenario "test", error: step is undefined: something unknown happens
10341034
Before step "step passes"
10351035
After step "step passes", error: <nil>, status: skipped
10361036
<<<< After suite`,
@@ -1039,15 +1039,15 @@ func TestTestSuite_Run(t *testing.T) {
10391039
name: "fail_then_undefined_fails_scenario", afterStepCnt: 2, beforeStepCnt: 2,
10401040
body: `
10411041
When step fails
1042-
Then step is undefined`,
1042+
Then something unknown happens`,
10431043
log: `
10441044
>>>> Before suite
10451045
>> Before scenario "test"
10461046
Before step "step fails"
10471047
After step "step fails", error: oops, status: failed
10481048
<< After scenario "test", error: oops
1049-
Before step "step is undefined"
1050-
After step "step is undefined", error: step is undefined, status: undefined
1049+
Before step "something unknown happens"
1050+
After step "something unknown happens", error: step is undefined: something unknown happens, status: undefined
10511051
<<<< After suite`,
10521052
},
10531053
{

0 commit comments

Comments
 (0)