Skip to content

Commit 4a4fd8a

Browse files
authored
fix(errors): Fix expected Step argument count for steps with context.Context (#679)
* fix(errors): print correct number of expected steps when step has defined * add unit test * remove duplicate part from unit test * update changelog
1 parent e03da74 commit 4a4fd8a

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
1212
- Step text is added to "step is undefined" error - ([669](https://github.com/cucumber/godog/pull/669) - [vearutop](https://github.com/vearutop))
1313

1414
### Fixed
15+
- fix(errors): fix(errors): Fix expected Step argument count for steps with `context.Context` ([679](https://github.com/cucumber/godog/pull/679) - [tigh-latte](https://github.com/tigh-latte))
1516
- 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))
1617

1718
## [v0.15.0]

internal/models/stepdef.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (sd *StepDefinition) Run(ctx context.Context) (context.Context, interface{}
5454
}
5555

5656
if len(sd.Args) < numIn {
57-
return ctx, fmt.Errorf("%w: expected %d arguments, matched %d from step", ErrUnmatchedStepArgumentNumber, typ.NumIn(), len(sd.Args))
57+
return ctx, fmt.Errorf("%w: expected %d arguments, matched %d from step", ErrUnmatchedStepArgumentNumber, numIn, len(sd.Args))
5858
}
5959

6060
for i := 0; i < numIn; i++ {

internal/models/stepdef_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,26 @@ func TestArgumentCountChecks(t *testing.T) {
259259
assert.Nil(t, err)
260260
}
261261

262+
func TestArgumentCountChecksWithContext(t *testing.T) {
263+
wasCalled := false
264+
fn := func(ctx context.Context, a int, b int) {
265+
wasCalled = true
266+
}
267+
268+
def := &models.StepDefinition{
269+
StepDefinition: formatters.StepDefinition{
270+
Handler: fn,
271+
},
272+
HandlerValue: reflect.ValueOf(fn),
273+
}
274+
275+
def.Args = []interface{}{"1"}
276+
_, err := def.Run(context.Background())
277+
assert.False(t, wasCalled)
278+
assert.Equal(t, `func expected more arguments than given: expected 2 arguments, matched 1 from step`, err.(error).Error())
279+
assert.True(t, errors.Is(err.(error), models.ErrUnmatchedStepArgumentNumber))
280+
}
281+
262282
func TestShouldSupportIntTypes(t *testing.T) {
263283
var aActual int64
264284
var bActual int32

0 commit comments

Comments
 (0)