diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd2f029..695d27c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) ### 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)) ## [v0.12.5] diff --git a/features/multistep.feature b/features/multistep.feature index 95885dd1..a9726788 100644 --- a/features/multistep.feature +++ b/features/multistep.feature @@ -138,3 +138,26 @@ Feature: run features with nested steps """ 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 diff --git a/run_test.go b/run_test.go index e36d1fca..b2f9bd2f 100644 --- a/run_test.go +++ b/run_test.go @@ -432,11 +432,11 @@ func Test_AllFeaturesRun(t *testing.T) { ...................................................................... 140 ...................................................................... 210 ...................................................................... 280 -................................................. 329 +....................................................... 335 -86 scenarios (86 passed) -329 steps (329 passed) +88 scenarios (88 passed) +335 steps (335 passed) 0s ` @@ -459,11 +459,11 @@ func Test_AllFeaturesRunAsSubtests(t *testing.T) { ...................................................................... 140 ...................................................................... 210 ...................................................................... 280 -................................................. 329 +....................................................... 335 -86 scenarios (86 passed) -329 steps (329 passed) +88 scenarios (88 passed) +335 steps (335 passed) 0s ` diff --git a/suite.go b/suite.go index ebb97c5d..261ed289 100644 --- a/suite.go +++ b/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) } + var err error + for _, text := range steps { if def := s.matchStepText(text); def == nil { 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) } } diff --git a/suite_context_test.go b/suite_context_test.go index e4ae8c7d..7a2fc7fa 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -132,6 +132,15 @@ func InitializeScenario(ctx *ScenarioContext) { 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) } @@ -339,6 +348,23 @@ func (tc *godogFeaturesScenario) theUndefinedStepSnippetsShouldBe(body *DocStrin 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 { var expected = strings.Split(steps.Content, "\n") var actual, unmatched, matched []string