From 887fd697fc97e5a60bcd1d578df5264aea97ecfe 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 | 7 +++++++ suite_context_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/features/multistep.feature b/features/multistep.feature index 95885dd1..e4c14b4b 100644 --- a/features/multistep.feature +++ b/features/multistep.feature @@ -138,3 +138,10 @@ Feature: run features with nested steps """ I should have 1 scenario registered """ + + Scenario: context passed between steps + Given I return a context from a step + Then I should see the context in the next step + + Scenario: context passed between multisteps + Given I can see contexts passed in multisteps \ No newline at end of file diff --git a/suite_context_test.go b/suite_context_test.go index e4ae8c7d..94c5204d 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -59,6 +59,15 @@ func InitializeScenario(ctx *ScenarioContext) { ctx.Step(`^the following steps? should be (passed|failed|skipped|undefined|pending):`, tc.followingStepsShouldHave) ctx.Step(`^the undefined step snippets should be:$`, tc.theUndefinedStepSnippetsShouldBe) + 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", + } + }) + // event stream ctx.Step(`^the following events should be fired:$`, tc.thereShouldBeEventsFired) @@ -339,6 +348,21 @@ func (tc *godogFeaturesScenario) theUndefinedStepSnippetsShouldBe(body *DocStrin return nil } +func (tc *godogFeaturesScenario) iReturnAContextFromAStep(ctx context.Context) (context.Context, error) { + return context.WithValue(ctx, "key", "value"), nil +} + +func (tc *godogFeaturesScenario) iShouldSeeTheContextInTheNextStep(ctx context.Context) error { + value, ok := ctx.Value("key").(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