test the before scenario hook
Этот коммит содержится в:
родитель
743083181e
коммит
3c405af6b2
2 изменённых файлов: 25 добавлений и 6 удалений
|
@ -8,10 +8,6 @@ Feature: suite hooks
|
||||||
And a feature path "features/load_features.feature:6"
|
And a feature path "features/load_features.feature:6"
|
||||||
And I parse features
|
And I parse features
|
||||||
|
|
||||||
Scenario: hi there
|
Scenario: triggers before scenario hook
|
||||||
When I run features
|
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
|
||||||
|
|
||||||
Scenario: and there
|
|
||||||
When I run features
|
|
||||||
Then I should have a scenario "" recorded in the hook
|
|
||||||
|
|
|
@ -46,6 +46,13 @@ func (s *suiteFeature) numParsed(args ...*Arg) (err error) {
|
||||||
return
|
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) {
|
func (s *suiteFeature) numScenariosRegistered(args ...*Arg) (err error) {
|
||||||
var num int
|
var num int
|
||||||
for _, ft := range s.features {
|
for _, ft := range s.features {
|
||||||
|
@ -57,6 +64,16 @@ func (s *suiteFeature) numScenariosRegistered(args ...*Arg) (err error) {
|
||||||
return
|
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) {
|
func SuiteContext(g Suite) {
|
||||||
s := &suiteFeature{
|
s := &suiteFeature{
|
||||||
suite: suite{},
|
suite: suite{},
|
||||||
|
@ -79,4 +96,10 @@ func SuiteContext(g Suite) {
|
||||||
g.Step(
|
g.Step(
|
||||||
regexp.MustCompile(`^I have a before scenario hook$`),
|
regexp.MustCompile(`^I have a before scenario hook$`),
|
||||||
StepHandlerFunc(s.iHaveBeforeScenarioHook))
|
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))
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче