Skip to content

Commit

Permalink
Add test for #487
Browse files Browse the repository at this point in the history
  • Loading branch information
wichert committed Jul 25, 2022
1 parent 918c867 commit 4717fa8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
23 changes: 23 additions & 0 deletions features/multistep.feature
Expand Up @@ -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
12 changes: 6 additions & 6 deletions run_test.go
Expand Up @@ -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
`

Expand All @@ -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
`

Expand Down
26 changes: 26 additions & 0 deletions suite_context_test.go
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4717fa8

Please sign in to comment.