Do not discard context from substeps (#488)
Этот коммит содержится в:
родитель
5e176da433
коммит
b2672bb933
5 изменённых файлов: 59 добавлений и 7 удалений
|
@ -12,6 +12,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
|
||||||
- README example is updated with `context.Context` and `go test` usage. ([477](https://github.com/cucumber/godog/pull/477) - [vearutop](https://github.com/vearutop))
|
- README example is updated with `context.Context` and `go test` usage. ([477](https://github.com/cucumber/godog/pull/477) - [vearutop](https://github.com/vearutop))
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- Fixed a bug which would ignore the context returned from a substep.([488](https://github.com/cucumber/godog/pull/488) - [wichert](https://github.com/wichert))
|
||||||
- Fixed a bug which would cause a panic when using the pretty formatter with a feature that contained a rule. ([480](https://github.com/cucumber/godog/pull/480) - [dumpsterfireproject](https://github.com/dumpsterfireproject))
|
- Fixed a bug which would cause a panic when using the pretty formatter with a feature that contained a rule. ([480](https://github.com/cucumber/godog/pull/480) - [dumpsterfireproject](https://github.com/dumpsterfireproject))
|
||||||
|
|
||||||
## [v0.12.5]
|
## [v0.12.5]
|
||||||
|
|
|
@ -138,3 +138,26 @@ Feature: run features with nested steps
|
||||||
"""
|
"""
|
||||||
I should have 1 scenario registered
|
I should have 1 scenario registered
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: context passed between steps
|
||||||
|
Given a feature "normal.feature" file:
|
||||||
|
"""
|
||||||
|
Feature: normal feature
|
||||||
|
|
||||||
|
Scenario: run passing multistep
|
||||||
|
Given I return a context from a step
|
||||||
|
Then I should see the context in the next step
|
||||||
|
"""
|
||||||
|
When I run feature suite
|
||||||
|
Then the suite should have passed
|
||||||
|
|
||||||
|
Scenario: context passed between steps
|
||||||
|
Given a feature "normal.feature" file:
|
||||||
|
"""
|
||||||
|
Feature: normal feature
|
||||||
|
|
||||||
|
Scenario: run passing multistep
|
||||||
|
Given I can see contexts passed in multisteps
|
||||||
|
"""
|
||||||
|
When I run feature suite
|
||||||
|
Then the suite should have passed
|
||||||
|
|
12
run_test.go
12
run_test.go
|
@ -432,11 +432,11 @@ func Test_AllFeaturesRun(t *testing.T) {
|
||||||
...................................................................... 140
|
...................................................................... 140
|
||||||
...................................................................... 210
|
...................................................................... 210
|
||||||
...................................................................... 280
|
...................................................................... 280
|
||||||
................................................. 329
|
....................................................... 335
|
||||||
|
|
||||||
|
|
||||||
86 scenarios (86 passed)
|
88 scenarios (88 passed)
|
||||||
329 steps (329 passed)
|
335 steps (335 passed)
|
||||||
0s
|
0s
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -459,11 +459,11 @@ func Test_AllFeaturesRunAsSubtests(t *testing.T) {
|
||||||
...................................................................... 140
|
...................................................................... 140
|
||||||
...................................................................... 210
|
...................................................................... 210
|
||||||
...................................................................... 280
|
...................................................................... 280
|
||||||
................................................. 329
|
....................................................... 335
|
||||||
|
|
||||||
|
|
||||||
86 scenarios (86 passed)
|
88 scenarios (88 passed)
|
||||||
329 steps (329 passed)
|
335 steps (335 passed)
|
||||||
0s
|
0s
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
4
suite.go
4
suite.go
|
@ -346,10 +346,12 @@ func (s *suite) maybeSubSteps(ctx context.Context, result interface{}) (context.
|
||||||
return ctx, fmt.Errorf("unexpected error, should have been []string: %T - %+v", result, result)
|
return ctx, fmt.Errorf("unexpected error, should have been []string: %T - %+v", result, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
for _, text := range steps {
|
for _, text := range steps {
|
||||||
if def := s.matchStepText(text); def == nil {
|
if def := s.matchStepText(text); def == nil {
|
||||||
return ctx, ErrUndefined
|
return ctx, ErrUndefined
|
||||||
} else if ctx, err := s.maybeSubSteps(def.Run(ctx)); err != nil {
|
} else if ctx, err = s.maybeSubSteps(def.Run(ctx)); err != nil {
|
||||||
return ctx, fmt.Errorf("%s: %+v", text, err)
|
return ctx, fmt.Errorf("%s: %+v", text, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,15 @@ func InitializeScenario(ctx *ScenarioContext) {
|
||||||
return context.WithValue(ctx, ctxKey("StepState"), true)
|
return context.WithValue(ctx, ctxKey("StepState"), true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ctx.Step(`^I return a context from a step$`, tc.iReturnAContextFromAStep)
|
||||||
|
ctx.Step(`^I should see the context in the next step$`, tc.iShouldSeeTheContextInTheNextStep)
|
||||||
|
ctx.Step(`^I can see contexts passed in multisteps$`, func() Steps {
|
||||||
|
return Steps{
|
||||||
|
"I return a context from a step",
|
||||||
|
"I should see the context in the next step",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
ctx.StepContext().Before(tc.inject)
|
ctx.StepContext().Before(tc.inject)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,6 +348,23 @@ func (tc *godogFeaturesScenario) theUndefinedStepSnippetsShouldBe(body *DocStrin
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type multiContextKey struct{}
|
||||||
|
|
||||||
|
func (tc *godogFeaturesScenario) iReturnAContextFromAStep(ctx context.Context) (context.Context, error) {
|
||||||
|
return context.WithValue(ctx, multiContextKey{}, "value"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tc *godogFeaturesScenario) iShouldSeeTheContextInTheNextStep(ctx context.Context) error {
|
||||||
|
value, ok := ctx.Value(multiContextKey{}).(string)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("context does not contain our key")
|
||||||
|
}
|
||||||
|
if value != "value" {
|
||||||
|
return errors.New("context has the wrong value for our key")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (tc *godogFeaturesScenario) followingStepsShouldHave(status string, steps *DocString) error {
|
func (tc *godogFeaturesScenario) followingStepsShouldHave(status string, steps *DocString) error {
|
||||||
var expected = strings.Split(steps.Content, "\n")
|
var expected = strings.Split(steps.Content, "\n")
|
||||||
var actual, unmatched, matched []string
|
var actual, unmatched, matched []string
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче