diff --git a/features/formatter/cucumber.feature b/features/formatter/cucumber.feature index 961fb91..b76e261 100644 --- a/features/formatter/cucumber.feature +++ b/features/formatter/cucumber.feature @@ -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" diff --git a/suite_context.go b/suite_context.go index 340c2e0..35afc19 100644 --- a/suite_context.go +++ b/suite_context.go @@ -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{} }