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.
Этот коммит содержится в:
Matthew Rothenberg 2017-05-04 15:01:11 -04:00
родитель 2b109b5ea8
коммит 304f1ea232
2 изменённых файлов: 23 добавлений и 11 удалений

Просмотреть файл

@ -257,7 +257,7 @@ Feature: cucumber json formatter
"name": "passing step", "name": "passing step",
"line": 7, "line": 7,
"match": { "match": {
"location": "suite_context.go:56" "location": "suite_context.go:67"
}, },
"result": { "result": {
"status": "passed", "status": "passed",
@ -269,7 +269,7 @@ Feature: cucumber json formatter
"name": "a failing step", "name": "a failing step",
"line": 8, "line": 8,
"match": { "match": {
"location": "suite_context.go:39" "location": "suite_context.go:50"
}, },
"result": { "result": {
"status": "failed", "status": "failed",
@ -325,7 +325,7 @@ Feature: cucumber json formatter
"name": "passing step", "name": "passing step",
"line": 11, "line": 11,
"match": { "match": {
"location": "suite_context.go:56" "location": "suite_context.go:67"
}, },
"result": { "result": {
"status": "passed", "status": "passed",
@ -347,7 +347,7 @@ Feature: cucumber json formatter
"name": "failing step", "name": "failing step",
"line": 12, "line": 12,
"match": { "match": {
"location": "suite_context.go:39" "location": "suite_context.go:50"
}, },
"result": { "result": {
"status": "failed", "status": "failed",
@ -448,7 +448,7 @@ Feature: cucumber json formatter
"line": 8 "line": 8
}, },
"match": { "match": {
"location": "suite_context.go:56" "location": "suite_context.go:67"
}, },
"result": { "result": {
"status": "passed", "status": "passed",
@ -501,7 +501,7 @@ Feature: cucumber json formatter
"name": "passing step", "name": "passing step",
"line": 7, "line": 7,
"match": { "match": {
"location": "suite_context.go:56" "location": "suite_context.go:67"
}, },
"result": { "result": {
"status": "passed", "status": "passed",
@ -535,7 +535,7 @@ Feature: cucumber json formatter
"name": "passing step", "name": "passing step",
"line": 10, "line": 10,
"match": { "match": {
"location": "suite_context.go:56" "location": "suite_context.go:67"
}, },
"result": { "result": {
"status": "skipped" "status": "skipped"

Просмотреть файл

@ -16,9 +16,20 @@ import (
// SuiteContext can be used for meta-testing of godog features/steps themselves. // SuiteContext can be used for meta-testing of godog features/steps themselves.
// //
// For an example, see godog's own `features/` and `suite_test.go`. // A typical user of the godog library should never need this, rather it is
func SuiteContext(s *Suite) { // provided for those developing add-on libraries for godog.
c := &suiteContext{} //
// 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) s.BeforeScenario(c.ResetBeforeEachScenario)
@ -89,6 +100,7 @@ type firedEvent struct {
type suiteContext struct { type suiteContext struct {
paths []string paths []string
testedSuite *Suite testedSuite *Suite
extraCIs []func(suite *Suite)
events []*firedEvent events []*firedEvent
out bytes.Buffer out bytes.Buffer
} }
@ -99,7 +111,7 @@ func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
s.paths = []string{} s.paths = []string{}
s.testedSuite = &Suite{} s.testedSuite = &Suite{}
// our tested suite will have the same context registered // our tested suite will have the same context registered
SuiteContext(s.testedSuite) SuiteContext(s.testedSuite, s.extraCIs...)
// reset all fired events // reset all fired events
s.events = []*firedEvent{} s.events = []*firedEvent{}
} }