Skip to content

Commit 72db47c

Browse files
authored
refactor: test_context.go (#564)
* 1. ScenarioContext has methods on both value and pointer receivers, make all methods have value receivers. 2. fix the syntax error in the comment 3. remove unused function Build Signed-off-by: longyue0521 <[email protected]> * convert ctx (type ScenarioContext) to StepContext Signed-off-by: longyue0521 <[email protected]> * rollback the deleted Build function Signed-off-by: longyue0521 <[email protected]> --------- Signed-off-by: longyue0521 <[email protected]>
1 parent ea50e4b commit 72db47c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

test_context.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (ctx ScenarioContext) Before(h BeforeScenarioHook) {
125125
// BeforeScenarioHook defines a hook before scenario.
126126
type BeforeScenarioHook func(ctx context.Context, sc *Scenario) (context.Context, error)
127127

128-
// After registers an function or method
128+
// After registers a function or method
129129
// to be run after every scenario.
130130
func (ctx ScenarioContext) After(h AfterScenarioHook) {
131131
ctx.suite.afterScenarioHandlers = append(ctx.suite.afterScenarioHandlers, h)
@@ -135,8 +135,8 @@ func (ctx ScenarioContext) After(h AfterScenarioHook) {
135135
type AfterScenarioHook func(ctx context.Context, sc *Scenario, err error) (context.Context, error)
136136

137137
// StepContext exposes StepContext of a scenario.
138-
func (ctx *ScenarioContext) StepContext() StepContext {
139-
return StepContext{suite: ctx.suite}
138+
func (ctx ScenarioContext) StepContext() StepContext {
139+
return StepContext(ctx)
140140
}
141141

142142
// Before registers a function or method
@@ -168,11 +168,11 @@ type AfterStepHook func(ctx context.Context, st *Step, status StepResultStatus,
168168
// to be run before every scenario.
169169
//
170170
// It is a good practice to restore the default state
171-
// before every scenario so it would be isolated from
171+
// before every scenario, so it would be isolated from
172172
// any kind of state.
173173
//
174174
// Deprecated: use Before.
175-
func (ctx *ScenarioContext) BeforeScenario(fn func(sc *Scenario)) {
175+
func (ctx ScenarioContext) BeforeScenario(fn func(sc *Scenario)) {
176176
ctx.Before(func(ctx context.Context, sc *Scenario) (context.Context, error) {
177177
fn(sc)
178178

@@ -184,7 +184,7 @@ func (ctx *ScenarioContext) BeforeScenario(fn func(sc *Scenario)) {
184184
// to be run after every scenario.
185185
//
186186
// Deprecated: use After.
187-
func (ctx *ScenarioContext) AfterScenario(fn func(sc *Scenario, err error)) {
187+
func (ctx ScenarioContext) AfterScenario(fn func(sc *Scenario, err error)) {
188188
ctx.After(func(ctx context.Context, sc *Scenario, err error) (context.Context, error) {
189189
fn(sc, err)
190190

@@ -196,7 +196,7 @@ func (ctx *ScenarioContext) AfterScenario(fn func(sc *Scenario, err error)) {
196196
// to be run before every step.
197197
//
198198
// Deprecated: use ScenarioContext.StepContext() and StepContext.Before.
199-
func (ctx *ScenarioContext) BeforeStep(fn func(st *Step)) {
199+
func (ctx ScenarioContext) BeforeStep(fn func(st *Step)) {
200200
ctx.StepContext().Before(func(ctx context.Context, st *Step) (context.Context, error) {
201201
fn(st)
202202

@@ -215,7 +215,7 @@ func (ctx *ScenarioContext) BeforeStep(fn func(st *Step)) {
215215
// browser, to take a screenshot after failure.
216216
//
217217
// Deprecated: use ScenarioContext.StepContext() and StepContext.After.
218-
func (ctx *ScenarioContext) AfterStep(fn func(st *Step, err error)) {
218+
func (ctx ScenarioContext) AfterStep(fn func(st *Step, err error)) {
219219
ctx.StepContext().After(func(ctx context.Context, st *Step, status StepResultStatus, err error) (context.Context, error) {
220220
fn(st, err)
221221

@@ -250,35 +250,35 @@ func (ctx *ScenarioContext) AfterStep(fn func(st *Step, err error)) {
250250
// If none of the *StepDefinition is matched, then
251251
// ErrUndefined error will be returned when
252252
// running steps.
253-
func (ctx *ScenarioContext) Step(expr, stepFunc interface{}) {
253+
func (ctx ScenarioContext) Step(expr, stepFunc interface{}) {
254254
ctx.stepWithKeyword(expr, stepFunc, formatters.None)
255255
}
256256

257257
// Given functions identically to Step, but the *StepDefinition
258258
// will only be matched if the step starts with "Given". "And"
259259
// and "But" keywords copy the keyword of the last step for the
260260
// purpose of matching.
261-
func (ctx *ScenarioContext) Given(expr, stepFunc interface{}) {
261+
func (ctx ScenarioContext) Given(expr, stepFunc interface{}) {
262262
ctx.stepWithKeyword(expr, stepFunc, formatters.Given)
263263
}
264264

265265
// When functions identically to Step, but the *StepDefinition
266266
// will only be matched if the step starts with "When". "And"
267267
// and "But" keywords copy the keyword of the last step for the
268268
// purpose of matching.
269-
func (ctx *ScenarioContext) When(expr, stepFunc interface{}) {
269+
func (ctx ScenarioContext) When(expr, stepFunc interface{}) {
270270
ctx.stepWithKeyword(expr, stepFunc, formatters.When)
271271
}
272272

273273
// Then functions identically to Step, but the *StepDefinition
274274
// will only be matched if the step starts with "Then". "And"
275275
// and "But" keywords copy the keyword of the last step for the
276276
// purpose of matching.
277-
func (ctx *ScenarioContext) Then(expr, stepFunc interface{}) {
277+
func (ctx ScenarioContext) Then(expr, stepFunc interface{}) {
278278
ctx.stepWithKeyword(expr, stepFunc, formatters.Then)
279279
}
280280

281-
func (ctx *ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface{}, keyword formatters.Keyword) {
281+
func (ctx ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface{}, keyword formatters.Keyword) {
282282
var regex *regexp.Regexp
283283

284284
switch t := expr.(type) {
@@ -338,7 +338,7 @@ func (ctx *ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface
338338
// If there are go test files, it first builds a test
339339
// package with standard go test command.
340340
//
341-
// Finally it generates godog suite executable which
341+
// Finally, it generates godog suite executable which
342342
// registers exported godog contexts from the test files
343343
// of tested package.
344344
//

0 commit comments

Comments
 (0)