Skip to content

Commit

Permalink
Add a test for BeforeStep in multisteps
Browse files Browse the repository at this point in the history
This demonstrates the bug reported in #486
  • Loading branch information
wichert committed Aug 17, 2022
1 parent 2028828 commit 11f00d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
13 changes: 13 additions & 0 deletions features/multistep.feature
Expand Up @@ -161,3 +161,16 @@ Feature: run features with nested steps
"""
When I run feature suite
Then the suite should have passed

Scenario: BeforeStep used for multisteps
Given a feature "normal.feature" file:
"""
Feature: normal feature
Scenario: invoke BeforeStep in multistep
Given I allow variable injection
And I run multisteps that set a value
Then the stored value is "someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety"
"""
When I run feature suite
Then the suite should have passed
12 changes: 6 additions & 6 deletions run_test.go
Expand Up @@ -518,11 +518,11 @@ func Test_AllFeaturesRun(t *testing.T) {
...................................................................... 140
...................................................................... 210
...................................................................... 280
....................................................... 335
.......................................................... 338
88 scenarios (88 passed)
335 steps (335 passed)
89 scenarios (89 passed)
338 steps (338 passed)
0s
`

Expand All @@ -545,11 +545,11 @@ func Test_AllFeaturesRunAsSubtests(t *testing.T) {
...................................................................... 140
...................................................................... 210
...................................................................... 280
....................................................... 335
.......................................................... 338
88 scenarios (88 passed)
335 steps (335 passed)
89 scenarios (89 passed)
338 steps (338 passed)
0s
`

Expand Down
23 changes: 23 additions & 0 deletions suite_context_test.go
Expand Up @@ -141,6 +141,12 @@ func InitializeScenario(ctx *ScenarioContext) {
}
})

ctx.Step(`I store value "([^"]*)"$`, tc.iStoreValue)
ctx.Step(`^the stored value is "([^"]*)"$`, tc.theStoredValueIs)
ctx.Step(`^I run multisteps that set a value$`, func() Steps {
return Steps{`I store value "{{X}}"`}
})

ctx.StepContext().Before(tc.inject)
}

Expand Down Expand Up @@ -365,6 +371,23 @@ func (tc *godogFeaturesScenario) iShouldSeeTheContextInTheNextStep(ctx context.C
return nil
}

type valueContextKey struct{}

func (tc *godogFeaturesScenario) iStoreValue(ctx context.Context, value string) context.Context {
return context.WithValue(ctx, valueContextKey{}, value)
}

func (tc *godogFeaturesScenario) theStoredValueIs(ctx context.Context, want string) error {
got, ok := ctx.Value(valueContextKey{}).(string)
if !ok {
return errors.New("context does not contain our key")
}
if got != want {
return fmt.Errorf("context has the wrong value for our key: got %s, want %s", got, want)
}
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 11f00d8

Please sign in to comment.