From 4717fa873d26a63c6f553b77006e362ed4018a9f Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Fri, 22 Jul 2022 14:17:14 +0200 Subject: [PATCH] Add test for #487 --- features/multistep.feature | 23 +++++++++++++++++++++++ run_test.go | 12 ++++++------ suite_context_test.go | 26 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) 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_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