|
| 1 | +We are excited to announce the release of godog v0.12.0. |
| 2 | + |
| 3 | +Here follows a summary of Notable Changes, the Non Backward Compatible Changes and Deprecation Notices. The full change |
| 4 | +log is available [here](https://github.com/cucumber/godog/blob/master/CHANGELOG.md). |
| 5 | + |
| 6 | + |
| 7 | +Notable Changes |
| 8 | +--------------- |
| 9 | + |
| 10 | +### Output with multiple formatters |
| 11 | + |
| 12 | +Now `godog` is able to use multiple formatters simultaneously with comma-separated formatters. |
| 13 | + |
| 14 | +`--format pretty,junit:report.xml,cucumber:report.json` will write `pretty` format to stdout, `junit` to report.xml |
| 15 | +and `cucumber` to report.json. |
| 16 | + |
| 17 | +### Contextualized hooks |
| 18 | + |
| 19 | +Scenario and Step hooks are now passing context to allow custom state communication. Returned context should generally |
| 20 | +be based or equal to received context. Context is also passed to steps that have it in declaration and is read from |
| 21 | +steps that return it. |
| 22 | + |
| 23 | +Hooks can now return error, if non nil error is returned test is failed. This enables additional flow control, for |
| 24 | +example to check expectations after the scenario. |
| 25 | + |
| 26 | +Scenario hooks are now named `Before` and `After`. |
| 27 | + |
| 28 | +```go |
| 29 | +// BeforeScenarioHook defines a hook before scenario. |
| 30 | +type BeforeScenarioHook func (ctx context.Context, sc *Scenario) (context.Context, error) |
| 31 | + |
| 32 | +// AfterScenarioHook defines a hook after scenario. |
| 33 | +type AfterScenarioHook func (ctx context.Context, sc *Scenario, err error) (context.Context, error) |
| 34 | +``` |
| 35 | + |
| 36 | +Step hooks are now also named `Before` and `After`, but they are available with `ScenarioContext.StepContext()`. |
| 37 | + |
| 38 | +```go |
| 39 | +// BeforeStepHook defines a hook before step. |
| 40 | +type BeforeStepHook func (ctx context.Context, st *Step) (context.Context, error) |
| 41 | + |
| 42 | +// AfterStepHook defines a hook after step. |
| 43 | +type AfterStepHook func (ctx context.Context, st *Step, status StepResultStatus, err error) (context.Context, error) |
| 44 | +``` |
| 45 | + |
| 46 | +### Step definition improvements |
| 47 | + |
| 48 | +Now `godog` can use additional ways to declare step definition. These declarations are optional and do not break |
| 49 | +backwards compatibility. |
| 50 | + |
| 51 | +Error result may be omitted if the step does not fail. |
| 52 | + |
| 53 | +```go |
| 54 | +func iEat(arg1 int) { |
| 55 | + // Eat arg1. |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +You can have `context.Context` as first argument, test runner will pass current context to the step. |
| 60 | + |
| 61 | +```go |
| 62 | +func iEat(ctx context.Context, arg1 int) { |
| 63 | + if v, ok := ctx.Value(eatKey{}).int; ok { |
| 64 | + // Eat v from context. |
| 65 | + } |
| 66 | + // Eat arg1. |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +You can have `context.Context` in return, test runner will use returned context to pass to next hooks and steps. |
| 71 | + |
| 72 | +```go |
| 73 | +func iEat(ctx context.Context, arg1 int) context.Context { |
| 74 | + if v, ok := ctx.Value(eatKey{}).int; ok { |
| 75 | + // Eat v from context. |
| 76 | + } |
| 77 | + // Eat arg1. |
| 78 | + |
| 79 | + return context.WithValue(ctx, eatKey{}, 0) |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +If error is also needed in return, context have to be first. |
| 84 | + |
| 85 | +```go |
| 86 | +func iEat(ctx context.Context, arg1 int) (context.Context, error) { |
| 87 | + if v, ok := ctx.Value(eatKey{}).int; ok { |
| 88 | + // Eat v from context. |
| 89 | + } |
| 90 | + // Eat arg1. |
| 91 | + |
| 92 | + if arg1 == 0 { |
| 93 | + return errors.New("can't eat nothing") |
| 94 | + } |
| 95 | + |
| 96 | + return context.WithValue(ctx, eatKey{}, 0), nil |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +You can now use `string` instead of `*godog.DocString` in declaration. |
| 101 | + |
| 102 | +### Getting features of test suite |
| 103 | + |
| 104 | +`godog.TestSuite` now can `RetrieveFeatures() ([]*models.Feature, error)` to expose parsed features to the user. |
| 105 | + |
| 106 | +### Added official support for go1.16 |
| 107 | + |
| 108 | +With the introduction of go1.16, go1.16 is now officially supported. |
| 109 | + |
| 110 | +Non Backward Compatible Changes |
| 111 | +------------------------------- |
| 112 | + |
| 113 | +### Messages library updated |
| 114 | + |
| 115 | +Messages library is changed from `github.com/cucumber/messages-go/v10` to `github.com/cucumber/messages-go/v16`. |
| 116 | + |
| 117 | +Deprecation Notices |
| 118 | +------------------- |
| 119 | + |
| 120 | +### Hooks |
| 121 | + |
| 122 | +Scenario and step hooks were upgraded with new API to support context and errors, previous methods are now deprecated. |
| 123 | + |
| 124 | +- `ScenarioContext.BeforeScenario`, use `ScenarioContext.Before` |
| 125 | +- `ScenarioContext.AfterScenario`, use `ScenarioContext.After` |
| 126 | +- `ScenarioContext.BeforeStep`, use `ScenarioContext.StepContext().Before` |
| 127 | +- `ScenarioContext.AfterStep`, use `ScenarioContext.StepContext().After` |
| 128 | + |
| 129 | +Full change log |
| 130 | +--------------- |
| 131 | + |
| 132 | +See [CHANGELOG.md](https://github.com/cucumber/godog/blob/master/CHANGELOG.md). |
0 commit comments