Invoke After Scenario hooks after After Step hooks (#444)
* Invoke After Scenario hooks after After Step hooks * Update CHANGELOG.md Co-authored-by: Matt Wynne <matt@cucumber.io>
Этот коммит содержится в:
родитель
82bcce7bdc
коммит
b850b44b48
4 изменённых файлов: 22 добавлений и 22 удалений
|
@ -12,6 +12,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
|
|||
|
||||
### Fixed
|
||||
|
||||
- After Scenario hook is called before After Step ([444](https://github.com/cucumber/godog/pull/444) - [vearutop])
|
||||
- `check-go-version` in Makefile to run on WSL. ([443](https://github.com/cucumber/godog/pull/443) - [mxygem])
|
||||
|
||||
## [v0.12.2]
|
||||
|
|
|
@ -72,9 +72,9 @@ Feature: suite events
|
|||
|
||||
Scenario: two
|
||||
Then passing step
|
||||
And failing step
|
||||
And adding step state to context
|
||||
And having correct context
|
||||
And failing step
|
||||
|
||||
Scenario Outline: three
|
||||
Then passing step
|
||||
|
|
22
suite.go
22
suite.go
|
@ -89,26 +89,24 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, prevS
|
|||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// run after step handlers
|
||||
rctx, err = s.runAfterStepHooks(ctx, step, sr.Status, err)
|
||||
}()
|
||||
earlyReturn := prevStepErr != nil || err == ErrUndefined
|
||||
|
||||
if prevStepErr != nil {
|
||||
return
|
||||
if !earlyReturn {
|
||||
sr = models.NewStepResult(pickle.Id, step.Id, match)
|
||||
}
|
||||
|
||||
if err == ErrUndefined {
|
||||
return
|
||||
}
|
||||
|
||||
sr = models.NewStepResult(pickle.Id, step.Id, match)
|
||||
// Run after step handlers.
|
||||
rctx, err = s.runAfterStepHooks(ctx, step, sr.Status, err)
|
||||
|
||||
// Trigger after scenario on failing or last step to attach possible hook error to step.
|
||||
if (err == nil && isLast) || err != nil {
|
||||
if sr.Status != StepSkipped && ((err == nil && isLast) || err != nil) {
|
||||
rctx, err = s.runAfterScenarioHooks(rctx, pickle, err)
|
||||
}
|
||||
|
||||
if earlyReturn {
|
||||
return
|
||||
}
|
||||
|
||||
switch err {
|
||||
case nil:
|
||||
sr.Status = models.Passed
|
||||
|
|
|
@ -423,12 +423,12 @@ func (tc *godogFeaturesScenario) iAmListeningToSuiteEvents() error {
|
|||
scenarioContext.Before(func(ctx context.Context, pickle *Scenario) (context.Context, error) {
|
||||
tc.events = append(tc.events, &firedEvent{"BeforeScenario", []interface{}{pickle}})
|
||||
|
||||
return context.WithValue(ctx, ctxKey("BeforeScenario"), true), nil
|
||||
return context.WithValue(ctx, ctxKey("BeforeScenario"), pickle.Name), nil
|
||||
})
|
||||
|
||||
scenarioContext.Before(func(ctx context.Context, sc *Scenario) (context.Context, error) {
|
||||
if sc.Name == "failing before and after scenario" || sc.Name == "failing before scenario" {
|
||||
return context.WithValue(ctx, ctxKey("AfterStep"), true), errors.New("failed in before scenario hook")
|
||||
return context.WithValue(ctx, ctxKey("AfterStep"), sc.Name), errors.New("failed in before scenario hook")
|
||||
}
|
||||
|
||||
return ctx, nil
|
||||
|
@ -453,7 +453,7 @@ func (tc *godogFeaturesScenario) iAmListeningToSuiteEvents() error {
|
|||
return ctx, errors.New("missing AfterStep in context")
|
||||
}
|
||||
|
||||
return context.WithValue(ctx, ctxKey("AfterScenario"), true), nil
|
||||
return context.WithValue(ctx, ctxKey("AfterScenario"), pickle.Name), nil
|
||||
})
|
||||
|
||||
scenarioContext.StepContext().Before(func(ctx context.Context, step *Step) (context.Context, error) {
|
||||
|
@ -463,7 +463,7 @@ func (tc *godogFeaturesScenario) iAmListeningToSuiteEvents() error {
|
|||
return ctx, errors.New("missing BeforeScenario in context")
|
||||
}
|
||||
|
||||
return context.WithValue(ctx, ctxKey("BeforeStep"), true), nil
|
||||
return context.WithValue(ctx, ctxKey("BeforeStep"), step.Text), nil
|
||||
})
|
||||
|
||||
scenarioContext.StepContext().After(func(ctx context.Context, step *Step, status StepResultStatus, err error) (context.Context, error) {
|
||||
|
@ -473,6 +473,10 @@ func (tc *godogFeaturesScenario) iAmListeningToSuiteEvents() error {
|
|||
return ctx, errors.New("missing BeforeScenario in context")
|
||||
}
|
||||
|
||||
if ctx.Value(ctxKey("AfterScenario")) != nil && status != models.Skipped {
|
||||
panic("unexpected premature AfterScenario during AfterStep: " + ctx.Value(ctxKey("AfterScenario")).(string))
|
||||
}
|
||||
|
||||
if ctx.Value(ctxKey("BeforeStep")) == nil {
|
||||
return ctx, errors.New("missing BeforeStep in context")
|
||||
}
|
||||
|
@ -485,7 +489,7 @@ func (tc *godogFeaturesScenario) iAmListeningToSuiteEvents() error {
|
|||
return ctx, errors.New("missing Step in context")
|
||||
}
|
||||
|
||||
return context.WithValue(ctx, ctxKey("AfterStep"), true), nil
|
||||
return context.WithValue(ctx, ctxKey("AfterStep"), step.Text), nil
|
||||
})
|
||||
|
||||
return nil
|
||||
|
@ -699,10 +703,7 @@ func (tc *godogFeaturesScenario) theRenderOutputWillBe(docstring *DocString) err
|
|||
actualTrimmed := actual
|
||||
actual = trimAllLines(actual)
|
||||
|
||||
expectedRows := strings.Split(expected, "\n")
|
||||
actualRows := strings.Split(actual, "\n")
|
||||
|
||||
return assertExpectedAndActual(assert.ElementsMatch, expectedRows, actualRows, actualTrimmed)
|
||||
return assertExpectedAndActual(assert.Equal, expected, actual, actualTrimmed)
|
||||
}
|
||||
|
||||
func (tc *godogFeaturesScenario) theRenderXMLWillBe(docstring *DocString) error {
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче