Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run BeforeStep for multisteps #491

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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