allow additional context initializers to be passed to SuiteContext
enables developers to inject extra context into the test environment when running suites in meta-tests.
Этот коммит содержится в:
родитель
2b109b5ea8
коммит
304f1ea232
2 изменённых файлов: 23 добавлений и 11 удалений
|
@ -257,7 +257,7 @@ Feature: cucumber json formatter
|
|||
"name": "passing step",
|
||||
"line": 7,
|
||||
"match": {
|
||||
"location": "suite_context.go:56"
|
||||
"location": "suite_context.go:67"
|
||||
},
|
||||
"result": {
|
||||
"status": "passed",
|
||||
|
@ -269,7 +269,7 @@ Feature: cucumber json formatter
|
|||
"name": "a failing step",
|
||||
"line": 8,
|
||||
"match": {
|
||||
"location": "suite_context.go:39"
|
||||
"location": "suite_context.go:50"
|
||||
},
|
||||
"result": {
|
||||
"status": "failed",
|
||||
|
@ -325,7 +325,7 @@ Feature: cucumber json formatter
|
|||
"name": "passing step",
|
||||
"line": 11,
|
||||
"match": {
|
||||
"location": "suite_context.go:56"
|
||||
"location": "suite_context.go:67"
|
||||
},
|
||||
"result": {
|
||||
"status": "passed",
|
||||
|
@ -347,7 +347,7 @@ Feature: cucumber json formatter
|
|||
"name": "failing step",
|
||||
"line": 12,
|
||||
"match": {
|
||||
"location": "suite_context.go:39"
|
||||
"location": "suite_context.go:50"
|
||||
},
|
||||
"result": {
|
||||
"status": "failed",
|
||||
|
@ -448,7 +448,7 @@ Feature: cucumber json formatter
|
|||
"line": 8
|
||||
},
|
||||
"match": {
|
||||
"location": "suite_context.go:56"
|
||||
"location": "suite_context.go:67"
|
||||
},
|
||||
"result": {
|
||||
"status": "passed",
|
||||
|
@ -501,7 +501,7 @@ Feature: cucumber json formatter
|
|||
"name": "passing step",
|
||||
"line": 7,
|
||||
"match": {
|
||||
"location": "suite_context.go:56"
|
||||
"location": "suite_context.go:67"
|
||||
},
|
||||
"result": {
|
||||
"status": "passed",
|
||||
|
@ -535,7 +535,7 @@ Feature: cucumber json formatter
|
|||
"name": "passing step",
|
||||
"line": 10,
|
||||
"match": {
|
||||
"location": "suite_context.go:56"
|
||||
"location": "suite_context.go:67"
|
||||
},
|
||||
"result": {
|
||||
"status": "skipped"
|
||||
|
|
|
@ -16,9 +16,20 @@ import (
|
|||
|
||||
// SuiteContext can be used for meta-testing of godog features/steps themselves.
|
||||
//
|
||||
// For an example, see godog's own `features/` and `suite_test.go`.
|
||||
func SuiteContext(s *Suite) {
|
||||
c := &suiteContext{}
|
||||
// A typical user of the godog library should never need this, rather it is
|
||||
// provided for those developing add-on libraries for godog.
|
||||
//
|
||||
// For an example of how to use, see godog's own `features/` and `suite_test.go`.
|
||||
func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite)) {
|
||||
c := &suiteContext{
|
||||
extraCIs: additionalContextInitializers,
|
||||
}
|
||||
|
||||
// apply any additional context intializers to modify the context that the
|
||||
// meta-tests will be run in
|
||||
for _, ci := range additionalContextInitializers {
|
||||
ci(s)
|
||||
}
|
||||
|
||||
s.BeforeScenario(c.ResetBeforeEachScenario)
|
||||
|
||||
|
@ -89,6 +100,7 @@ type firedEvent struct {
|
|||
type suiteContext struct {
|
||||
paths []string
|
||||
testedSuite *Suite
|
||||
extraCIs []func(suite *Suite)
|
||||
events []*firedEvent
|
||||
out bytes.Buffer
|
||||
}
|
||||
|
@ -99,7 +111,7 @@ func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
|
|||
s.paths = []string{}
|
||||
s.testedSuite = &Suite{}
|
||||
// our tested suite will have the same context registered
|
||||
SuiteContext(s.testedSuite)
|
||||
SuiteContext(s.testedSuite, s.extraCIs...)
|
||||
// reset all fired events
|
||||
s.events = []*firedEvent{}
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче