Skip to content

Commit 5c35207

Browse files
committed
support for tags in outline examples, closes #133
1 parent 857a19d commit 5c35207

File tree

7 files changed

+163
-7
lines changed

7 files changed

+163
-7
lines changed

features/formatter/events.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Feature: event stream formatter
1414
"""
1515

1616
Scenario: should process simple scenario
17-
Given a feature path "features/load.feature:23"
17+
Given a feature path "features/load.feature:24"
1818
When I run feature suite with formatter "events"
1919
Then the following events should be fired:
2020
"""
@@ -35,7 +35,7 @@ Feature: event stream formatter
3535
"""
3636

3737
Scenario: should process outline scenario
38-
Given a feature path "features/load.feature:31"
38+
Given a feature path "features/load.feature:32"
3939
When I run feature suite with formatter "events"
4040
Then the following events should be fired:
4141
"""

features/lang.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Savybė: užkrauti savybes
88
Scenarijus: savybių užkrovimas iš aplanko
99
Duota savybių aplankas "features"
1010
Kai aš išskaitau savybes
11-
Tada aš turėčiau turėti 10 savybių failus:
11+
Tada aš turėčiau turėti 11 savybių failus:
1212
"""
1313
features/background.feature
1414
features/events.feature
@@ -20,4 +20,5 @@ Savybė: užkrauti savybes
2020
features/outline.feature
2121
features/run.feature
2222
features/snippets.feature
23+
features/tags.feature
2324
"""

features/load.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: load features
66
Scenario: load features within path
77
Given a feature path "features"
88
When I parse features
9-
Then I should have 10 feature files:
9+
Then I should have 11 feature files:
1010
"""
1111
features/background.feature
1212
features/events.feature
@@ -18,6 +18,7 @@ Feature: load features
1818
features/outline.feature
1919
features/run.feature
2020
features/snippets.feature
21+
features/tags.feature
2122
"""
2223

2324
Scenario: load a specific feature file

features/outline.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,4 @@ Feature: run outline
150150
| path | scen |
151151
| features/load.feature:6 | 1 |
152152
| features/load.feature | 6 |
153+

features/tags.feature

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
Feature: tag filters
2+
In order to test application behavior
3+
As a test suite
4+
I need to be able to filter features and scenarios by tags
5+
6+
Scenario: should filter outline examples by tags
7+
Given a feature "normal.feature" file:
8+
"""
9+
Feature: outline
10+
11+
Background:
12+
Given passing step
13+
14+
Scenario Outline: parse a scenario
15+
Given a feature path "<path>"
16+
When I parse features
17+
Then I should have <num> scenario registered
18+
19+
Examples:
20+
| path | num |
21+
| features/load.feature:3 | 0 |
22+
23+
@used
24+
Examples:
25+
| path | num |
26+
| features/load.feature:6 | 1 |
27+
"""
28+
When I run feature suite with tags "@used"
29+
Then the suite should have passed
30+
And the following steps should be passed:
31+
"""
32+
I parse features
33+
a feature path "features/load.feature:6"
34+
I should have 1 scenario registered
35+
"""
36+
And I should have 1 scenario registered
37+
38+
Scenario: should filter scenarios by X tag
39+
Given a feature "normal.feature" file:
40+
"""
41+
Feature: tagged
42+
43+
@x
44+
Scenario: one
45+
Given a feature path "one"
46+
47+
@x
48+
Scenario: two
49+
Given a feature path "two"
50+
51+
@x @y
52+
Scenario: three
53+
Given a feature path "three"
54+
55+
@y
56+
Scenario: four
57+
Given a feature path "four"
58+
"""
59+
When I run feature suite with tags "@x"
60+
Then the suite should have passed
61+
And I should have 3 scenario registered
62+
And the following steps should be passed:
63+
"""
64+
a feature path "one"
65+
a feature path "two"
66+
a feature path "three"
67+
"""
68+
69+
Scenario: should filter scenarios by X tag not having Y
70+
Given a feature "normal.feature" file:
71+
"""
72+
Feature: tagged
73+
74+
@x
75+
Scenario: one
76+
Given a feature path "one"
77+
78+
@x
79+
Scenario: two
80+
Given a feature path "two"
81+
82+
@x @y
83+
Scenario: three
84+
Given a feature path "three"
85+
86+
@y @z
87+
Scenario: four
88+
Given a feature path "four"
89+
"""
90+
When I run feature suite with tags "@x && ~@y"
91+
Then the suite should have passed
92+
And I should have 2 scenario registered
93+
And the following steps should be passed:
94+
"""
95+
a feature path "one"
96+
a feature path "two"
97+
"""
98+
99+
Scenario: should filter scenarios having Y and Z tags
100+
Given a feature "normal.feature" file:
101+
"""
102+
Feature: tagged
103+
104+
@x
105+
Scenario: one
106+
Given a feature path "one"
107+
108+
@x
109+
Scenario: two
110+
Given a feature path "two"
111+
112+
@x @y
113+
Scenario: three
114+
Given a feature path "three"
115+
116+
@y @z
117+
Scenario: four
118+
Given a feature path "four"
119+
"""
120+
When I run feature suite with tags "@y && @z"
121+
Then the suite should have passed
122+
And I should have 1 scenario registered
123+
And the following steps should be passed:
124+
"""
125+
a feature path "four"
126+
"""

suite.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ func filterFeatures(tags string, collected map[string]*feature) (features []*fea
716716
}
717717
ft.ScenarioDefinitions = scenarios
718718
applyTagFilter(tags, ft.Feature)
719-
720719
features = append(features, ft)
721720
}
722721

@@ -732,8 +731,22 @@ func applyTagFilter(tags string, ft *gherkin.Feature) {
732731

733732
var scenarios []interface{}
734733
for _, scenario := range ft.ScenarioDefinitions {
735-
if matchesTags(tags, allTags(ft, scenario)) {
736-
scenarios = append(scenarios, scenario)
734+
switch t := scenario.(type) {
735+
case *gherkin.ScenarioOutline:
736+
var allExamples []*gherkin.Examples
737+
for _, examples := range t.Examples {
738+
if matchesTags(tags, allTags(ft, t, examples)) {
739+
allExamples = append(allExamples, examples)
740+
}
741+
}
742+
t.Examples = allExamples
743+
if len(t.Examples) > 0 {
744+
scenarios = append(scenarios, scenario)
745+
}
746+
case *gherkin.Scenario:
747+
if matchesTags(tags, allTags(ft, t)) {
748+
scenarios = append(scenarios, scenario)
749+
}
737750
}
738751
}
739752
ft.ScenarioDefinitions = scenarios

suite_context.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite))
3939
s.Step(`^I parse features$`, c.parseFeatures)
4040
s.Step(`^I'm listening to suite events$`, c.iAmListeningToSuiteEvents)
4141
s.Step(`^I run feature suite$`, c.iRunFeatureSuite)
42+
s.Step(`^I run feature suite with tags "([^"]*)"$`, c.iRunFeatureSuiteWithTags)
4243
s.Step(`^I run feature suite with formatter "([^"]*)"$`, c.iRunFeatureSuiteWithFormatter)
4344
s.Step(`^(?:a )?feature "([^"]*)"(?: file)?:$`, c.aFeatureFile)
4445
s.Step(`^the suite should have (passed|failed)$`, c.theSuiteShouldHave)
@@ -114,6 +115,19 @@ func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
114115
s.events = []*firedEvent{}
115116
}
116117

118+
func (s *suiteContext) iRunFeatureSuiteWithTags(tags string) error {
119+
if err := s.parseFeatures(); err != nil {
120+
return err
121+
}
122+
for _, feat := range s.testedSuite.features {
123+
applyTagFilter(tags, feat.Feature)
124+
}
125+
s.testedSuite.fmt = testFormatterFunc("godog", &s.out)
126+
s.testedSuite.run()
127+
s.testedSuite.fmt.Summary()
128+
return nil
129+
}
130+
117131
func (s *suiteContext) iRunFeatureSuiteWithFormatter(name string) error {
118132
f := FindFmt(name)
119133
if f == nil {

0 commit comments

Comments
 (0)