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
Этот коммит содержится в:
родитель
e03da742a5
коммит
4a4fd8ab3a
3 изменённых файлов: 22 добавлений и 1 удалений
|
@ -12,6 +12,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
|
|||
- Step text is added to "step is undefined" error - ([669](https://github.com/cucumber/godog/pull/669) - [vearutop](https://github.com/vearutop))
|
||||
|
||||
### Fixed
|
||||
- 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))
|
||||
- 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]
|
||||
|
|
|
@ -54,7 +54,7 @@ func (sd *StepDefinition) Run(ctx context.Context) (context.Context, interface{}
|
|||
}
|
||||
|
||||
if len(sd.Args) < numIn {
|
||||
return ctx, fmt.Errorf("%w: expected %d arguments, matched %d from step", ErrUnmatchedStepArgumentNumber, typ.NumIn(), len(sd.Args))
|
||||
return ctx, fmt.Errorf("%w: expected %d arguments, matched %d from step", ErrUnmatchedStepArgumentNumber, numIn, len(sd.Args))
|
||||
}
|
||||
|
||||
for i := 0; i < numIn; i++ {
|
||||
|
|
|
@ -259,6 +259,26 @@ func TestArgumentCountChecks(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestArgumentCountChecksWithContext(t *testing.T) {
|
||||
wasCalled := false
|
||||
fn := func(ctx context.Context, a int, b int) {
|
||||
wasCalled = true
|
||||
}
|
||||
|
||||
def := &models.StepDefinition{
|
||||
StepDefinition: formatters.StepDefinition{
|
||||
Handler: fn,
|
||||
},
|
||||
HandlerValue: reflect.ValueOf(fn),
|
||||
}
|
||||
|
||||
def.Args = []interface{}{"1"}
|
||||
_, err := def.Run(context.Background())
|
||||
assert.False(t, wasCalled)
|
||||
assert.Equal(t, `func expected more arguments than given: expected 2 arguments, matched 1 from step`, err.(error).Error())
|
||||
assert.True(t, errors.Is(err.(error), models.ErrUnmatchedStepArgumentNumber))
|
||||
}
|
||||
|
||||
func TestShouldSupportIntTypes(t *testing.T) {
|
||||
var aActual int64
|
||||
var bActual int32
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче