Skip to content

Commit 11f00d8

Browse files
committed
Add a test for BeforeStep in multisteps
This demonstrates the bug reported in #486
1 parent 2028828 commit 11f00d8

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

features/multistep.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,16 @@ Feature: run features with nested steps
161161
"""
162162
When I run feature suite
163163
Then the suite should have passed
164+
165+
Scenario: BeforeStep used for multisteps
166+
Given a feature "normal.feature" file:
167+
"""
168+
Feature: normal feature
169+
170+
Scenario: invoke BeforeStep in multistep
171+
Given I allow variable injection
172+
And I run multisteps that set a value
173+
Then the stored value is "someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety"
174+
"""
175+
When I run feature suite
176+
Then the suite should have passed

run_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,11 @@ func Test_AllFeaturesRun(t *testing.T) {
518518
...................................................................... 140
519519
...................................................................... 210
520520
...................................................................... 280
521-
....................................................... 335
521+
.......................................................... 338
522522
523523
524-
88 scenarios (88 passed)
525-
335 steps (335 passed)
524+
89 scenarios (89 passed)
525+
338 steps (338 passed)
526526
0s
527527
`
528528

@@ -545,11 +545,11 @@ func Test_AllFeaturesRunAsSubtests(t *testing.T) {
545545
...................................................................... 140
546546
...................................................................... 210
547547
...................................................................... 280
548-
....................................................... 335
548+
.......................................................... 338
549549
550550
551-
88 scenarios (88 passed)
552-
335 steps (335 passed)
551+
89 scenarios (89 passed)
552+
338 steps (338 passed)
553553
0s
554554
`
555555

suite_context_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ func InitializeScenario(ctx *ScenarioContext) {
141141
}
142142
})
143143

144+
ctx.Step(`I store value "([^"]*)"$`, tc.iStoreValue)
145+
ctx.Step(`^the stored value is "([^"]*)"$`, tc.theStoredValueIs)
146+
ctx.Step(`^I run multisteps that set a value$`, func() Steps {
147+
return Steps{`I store value "{{X}}"`}
148+
})
149+
144150
ctx.StepContext().Before(tc.inject)
145151
}
146152

@@ -365,6 +371,23 @@ func (tc *godogFeaturesScenario) iShouldSeeTheContextInTheNextStep(ctx context.C
365371
return nil
366372
}
367373

374+
type valueContextKey struct{}
375+
376+
func (tc *godogFeaturesScenario) iStoreValue(ctx context.Context, value string) context.Context {
377+
return context.WithValue(ctx, valueContextKey{}, value)
378+
}
379+
380+
func (tc *godogFeaturesScenario) theStoredValueIs(ctx context.Context, want string) error {
381+
got, ok := ctx.Value(valueContextKey{}).(string)
382+
if !ok {
383+
return errors.New("context does not contain our key")
384+
}
385+
if got != want {
386+
return fmt.Errorf("context has the wrong value for our key: got %s, want %s", got, want)
387+
}
388+
return nil
389+
}
390+
368391
func (tc *godogFeaturesScenario) followingStepsShouldHave(status string, steps *DocString) error {
369392
var expected = strings.Split(steps.Content, "\n")
370393
var actual, unmatched, matched []string

0 commit comments

Comments
 (0)