Skip to content

Commit

Permalink
Merge pull request #312 from cucumber/removed-deprecated-feature-hooks
Browse files Browse the repository at this point in the history
Removed the deprecated feature hooks
  • Loading branch information
lonnblad authored Jun 20, 2020
2 parents 6e01c51 + 1d724e2 commit d9e0ff7
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 65 deletions.
10 changes: 0 additions & 10 deletions features/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 1 |
| BeforeScenario | 1 |
| BeforeStep | 3 |
| AfterStep | 3 |
| AfterScenario | 1 |
| AfterFeature | 1 |
| AfterSuite | 1 |

Scenario: triggers appropriate events whole feature
Given a feature path "features/load.feature"
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 1 |
| BeforeScenario | 6 |
| BeforeStep | 19 |
| AfterStep | 19 |
| AfterScenario | 6 |
| AfterFeature | 1 |
| AfterSuite | 1 |

Scenario: triggers appropriate events for two feature files
Expand All @@ -43,12 +39,10 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 2 |
| BeforeScenario | 2 |
| BeforeStep | 7 |
| AfterStep | 7 |
| AfterScenario | 2 |
| AfterFeature | 2 |
| AfterSuite | 1 |

Scenario: should not trigger events on empty feature
Expand All @@ -63,12 +57,10 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 0 |
| BeforeScenario | 0 |
| BeforeStep | 0 |
| AfterStep | 0 |
| AfterScenario | 0 |
| AfterFeature | 0 |
| AfterSuite | 1 |

Scenario: should not trigger events on empty scenarios
Expand All @@ -91,10 +83,8 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 1 |
| BeforeScenario | 2 |
| BeforeStep | 2 |
| AfterStep | 2 |
| AfterScenario | 2 |
| AfterFeature | 1 |
| AfterSuite | 1 |
47 changes: 0 additions & 47 deletions suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ type Suite struct {

// suite event handlers
beforeSuiteHandlers []func()
beforeFeatureHandlers []func(*messages.GherkinDocument)
beforeScenarioHandlers []func(*messages.Pickle)
beforeStepHandlers []func(*messages.Pickle_PickleStep)
afterStepHandlers []func(*messages.Pickle_PickleStep, error)
afterScenarioHandlers []func(*messages.Pickle, error)
afterFeatureHandlers []func(*messages.GherkinDocument)
afterSuiteHandlers []func()
}

Expand Down Expand Up @@ -137,27 +135,6 @@ func (s *Suite) BeforeSuite(fn func()) {
s.beforeSuiteHandlers = append(s.beforeSuiteHandlers, fn)
}

// BeforeFeature registers a function or method
// to be run once before every feature execution.
//
// If godog is run with concurrency option, it will
// run every feature per goroutine. So user may choose
// whether to isolate state within feature context or
// scenario.
//
// Best practice is not to have any state dependency on
// every scenario, but in some cases if VM for example
// needs to be started it may take very long for each
// scenario to restart it.
//
// Use it wisely and avoid sharing state between scenarios.
//
// Deprecated: BeforeFeature will be removed. Depending on
// your usecase, do setup in BeforeSuite or BeforeScenario.
func (s *Suite) BeforeFeature(fn func(*messages.GherkinDocument)) {
s.beforeFeatureHandlers = append(s.beforeFeatureHandlers, fn)
}

// BeforeScenario registers a function or method
// to be run before every pickle.
//
Expand Down Expand Up @@ -209,16 +186,6 @@ func (s *Suite) AfterScenario(fn func(*messages.Pickle, error)) {
s.afterScenarioHandlers = append(s.afterScenarioHandlers, fn)
}

// AfterFeature registers a function or method
// to be run once after feature executed all scenarios.
//
// Deprecated: AfterFeature will be removed. Depending on
// your usecase, do cleanup and teardowns in AfterScenario
// or AfterSuite.
func (s *Suite) AfterFeature(fn func(*messages.GherkinDocument)) {
s.afterFeatureHandlers = append(s.afterFeatureHandlers, fn)
}

// AfterSuite registers a function or method
// to be run once after suite runner
//
Expand Down Expand Up @@ -455,22 +422,8 @@ func (s *Suite) shouldFail(err error) bool {
}

func (s *Suite) runFeature(f *feature) {
if !isEmptyFeature(f.pickles) {
for _, fn := range s.beforeFeatureHandlers {
fn(f.GherkinDocument)
}
}

s.fmt.Feature(f.GherkinDocument, f.Uri, f.content)

defer func() {
if !isEmptyFeature(f.pickles) {
for _, fn := range s.afterFeatureHandlers {
fn(f.GherkinDocument)
}
}
}()

for _, pickle := range f.pickles {
err := s.runPickle(pickle)
if s.shouldFail(err) {
Expand Down
8 changes: 0 additions & 8 deletions suite_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,6 @@ func (s *suiteContext) iAmListeningToSuiteEvents() error {
s.events = append(s.events, &firedEvent{"AfterSuite", []interface{}{}})
})

s.testedSuite.BeforeFeature(func(ft *messages.GherkinDocument) {
s.events = append(s.events, &firedEvent{"BeforeFeature", []interface{}{ft}})
})

s.testedSuite.AfterFeature(func(ft *messages.GherkinDocument) {
s.events = append(s.events, &firedEvent{"AfterFeature", []interface{}{ft}})
})

s.testedSuite.BeforeScenario(func(pickle *Scenario) {
s.events = append(s.events, &firedEvent{"BeforeScenario", []interface{}{pickle}})
})
Expand Down

0 comments on commit d9e0ff7

Please sign in to comment.