support for tags in outline examples, closes #133

Этот коммит содержится в:
gedi 2018-09-28 16:17:13 +03:00
родитель 857a19d0bf
коммит 5c352074bc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 56604CDCCC201556
7 изменённых файлов: 163 добавлений и 7 удалений

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

@ -14,7 +14,7 @@ Feature: event stream formatter
"""
Scenario: should process simple scenario
Given a feature path "features/load.feature:23"
Given a feature path "features/load.feature:24"
When I run feature suite with formatter "events"
Then the following events should be fired:
"""
@ -35,7 +35,7 @@ Feature: event stream formatter
"""
Scenario: should process outline scenario
Given a feature path "features/load.feature:31"
Given a feature path "features/load.feature:32"
When I run feature suite with formatter "events"
Then the following events should be fired:
"""

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

@ -8,7 +8,7 @@ Savybė: užkrauti savybes
Scenarijus: savybių užkrovimas iš aplanko
Duota savybių aplankas "features"
Kai aš išskaitau savybes
Tada aš turėčiau turėti 10 savybių failus:
Tada aš turėčiau turėti 11 savybių failus:
"""
features/background.feature
features/events.feature
@ -20,4 +20,5 @@ Savybė: užkrauti savybes
features/outline.feature
features/run.feature
features/snippets.feature
features/tags.feature
"""

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

@ -6,7 +6,7 @@ Feature: load features
Scenario: load features within path
Given a feature path "features"
When I parse features
Then I should have 10 feature files:
Then I should have 11 feature files:
"""
features/background.feature
features/events.feature
@ -18,6 +18,7 @@ Feature: load features
features/outline.feature
features/run.feature
features/snippets.feature
features/tags.feature
"""
Scenario: load a specific feature file

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

@ -150,3 +150,4 @@ Feature: run outline
| path | scen |
| features/load.feature:6 | 1 |
| features/load.feature | 6 |

126
features/tags.feature Обычный файл
Просмотреть файл

@ -0,0 +1,126 @@
Feature: tag filters
In order to test application behavior
As a test suite
I need to be able to filter features and scenarios by tags
Scenario: should filter outline examples by tags
Given a feature "normal.feature" file:
"""
Feature: outline
Background:
Given passing step
Scenario Outline: parse a scenario
Given a feature path "<path>"
When I parse features
Then I should have <num> scenario registered
Examples:
| path | num |
| features/load.feature:3 | 0 |
@used
Examples:
| path | num |
| features/load.feature:6 | 1 |
"""
When I run feature suite with tags "@used"
Then the suite should have passed
And the following steps should be passed:
"""
I parse features
a feature path "features/load.feature:6"
I should have 1 scenario registered
"""
And I should have 1 scenario registered
Scenario: should filter scenarios by X tag
Given a feature "normal.feature" file:
"""
Feature: tagged
@x
Scenario: one
Given a feature path "one"
@x
Scenario: two
Given a feature path "two"
@x @y
Scenario: three
Given a feature path "three"
@y
Scenario: four
Given a feature path "four"
"""
When I run feature suite with tags "@x"
Then the suite should have passed
And I should have 3 scenario registered
And the following steps should be passed:
"""
a feature path "one"
a feature path "two"
a feature path "three"
"""
Scenario: should filter scenarios by X tag not having Y
Given a feature "normal.feature" file:
"""
Feature: tagged
@x
Scenario: one
Given a feature path "one"
@x
Scenario: two
Given a feature path "two"
@x @y
Scenario: three
Given a feature path "three"
@y @z
Scenario: four
Given a feature path "four"
"""
When I run feature suite with tags "@x && ~@y"
Then the suite should have passed
And I should have 2 scenario registered
And the following steps should be passed:
"""
a feature path "one"
a feature path "two"
"""
Scenario: should filter scenarios having Y and Z tags
Given a feature "normal.feature" file:
"""
Feature: tagged
@x
Scenario: one
Given a feature path "one"
@x
Scenario: two
Given a feature path "two"
@x @y
Scenario: three
Given a feature path "three"
@y @z
Scenario: four
Given a feature path "four"
"""
When I run feature suite with tags "@y && @z"
Then the suite should have passed
And I should have 1 scenario registered
And the following steps should be passed:
"""
a feature path "four"
"""

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

@ -716,7 +716,6 @@ func filterFeatures(tags string, collected map[string]*feature) (features []*fea
}
ft.ScenarioDefinitions = scenarios
applyTagFilter(tags, ft.Feature)
features = append(features, ft)
}
@ -732,9 +731,23 @@ func applyTagFilter(tags string, ft *gherkin.Feature) {
var scenarios []interface{}
for _, scenario := range ft.ScenarioDefinitions {
if matchesTags(tags, allTags(ft, scenario)) {
switch t := scenario.(type) {
case *gherkin.ScenarioOutline:
var allExamples []*gherkin.Examples
for _, examples := range t.Examples {
if matchesTags(tags, allTags(ft, t, examples)) {
allExamples = append(allExamples, examples)
}
}
t.Examples = allExamples
if len(t.Examples) > 0 {
scenarios = append(scenarios, scenario)
}
case *gherkin.Scenario:
if matchesTags(tags, allTags(ft, t)) {
scenarios = append(scenarios, scenario)
}
}
}
ft.ScenarioDefinitions = scenarios
}

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

@ -39,6 +39,7 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite))
s.Step(`^I parse features$`, c.parseFeatures)
s.Step(`^I'm listening to suite events$`, c.iAmListeningToSuiteEvents)
s.Step(`^I run feature suite$`, c.iRunFeatureSuite)
s.Step(`^I run feature suite with tags "([^"]*)"$`, c.iRunFeatureSuiteWithTags)
s.Step(`^I run feature suite with formatter "([^"]*)"$`, c.iRunFeatureSuiteWithFormatter)
s.Step(`^(?:a )?feature "([^"]*)"(?: file)?:$`, c.aFeatureFile)
s.Step(`^the suite should have (passed|failed)$`, c.theSuiteShouldHave)
@ -114,6 +115,19 @@ func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
s.events = []*firedEvent{}
}
func (s *suiteContext) iRunFeatureSuiteWithTags(tags string) error {
if err := s.parseFeatures(); err != nil {
return err
}
for _, feat := range s.testedSuite.features {
applyTagFilter(tags, feat.Feature)
}
s.testedSuite.fmt = testFormatterFunc("godog", &s.out)
s.testedSuite.run()
s.testedSuite.fmt.Summary()
return nil
}
func (s *suiteContext) iRunFeatureSuiteWithFormatter(name string) error {
f := FindFmt(name)
if f == nil {