From 3c405af6b2a54bfa8537b3dd84c48c0872d2913b Mon Sep 17 00:00:00 2001 From: gedi Date: Wed, 17 Jun 2015 18:18:28 +0300 Subject: [PATCH] test the before scenario hook --- features/hooks.feature | 8 ++------ suite_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/features/hooks.feature b/features/hooks.feature index cdcbb00..1022d14 100644 --- a/features/hooks.feature +++ b/features/hooks.feature @@ -8,10 +8,6 @@ Feature: suite hooks And a feature path "features/load_features.feature:6" And I parse features - Scenario: hi there + Scenario: triggers before scenario hook When I run features - Then I should have a scenario "" recorded in the hook - - Scenario: and there - When I run features - Then I should have a scenario "" recorded in the hook + Then I should have a scenario "load features within path" recorded in the hook diff --git a/suite_test.go b/suite_test.go index 03f7df6..dd1e3ab 100644 --- a/suite_test.go +++ b/suite_test.go @@ -46,6 +46,13 @@ func (s *suiteFeature) numParsed(args ...*Arg) (err error) { return } +func (s *suiteFeature) iRunFeatures(args ...*Arg) error { + for _, f := range s.features { + s.runFeature(f) + } + return nil +} + func (s *suiteFeature) numScenariosRegistered(args ...*Arg) (err error) { var num int for _, ft := range s.features { @@ -57,6 +64,16 @@ func (s *suiteFeature) numScenariosRegistered(args ...*Arg) (err error) { return } +func (s *suiteFeature) iShouldHaveScenarioRecordedInHook(args ...*Arg) (err error) { + if s.befScenarioHook == nil { + return fmt.Errorf("there was no scenario executed in before hook") + } + if s.befScenarioHook.Title != args[0].String() { + err = fmt.Errorf(`expected "%s" scenario to be run in hook, but got "%s"`, args[0].String(), s.befScenarioHook.Title) + } + return +} + func SuiteContext(g Suite) { s := &suiteFeature{ suite: suite{}, @@ -79,4 +96,10 @@ func SuiteContext(g Suite) { g.Step( regexp.MustCompile(`^I have a before scenario hook$`), StepHandlerFunc(s.iHaveBeforeScenarioHook)) + g.Step( + regexp.MustCompile(`^I run features$`), + StepHandlerFunc(s.iRunFeatures)) + g.Step( + regexp.MustCompile(`^I should have a scenario "([^"]*)" recorded in the hook$`), + StepHandlerFunc(s.iShouldHaveScenarioRecordedInHook)) }