bryanl-gherkin 2.11.1.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitattributes +2 -0
- data/.mailmap +2 -0
- data/.rbenv-gemsets +1 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +16 -0
- data/.yardopts +5 -0
- data/Gemfile +5 -0
- data/History.md +788 -0
- data/LICENSE +20 -0
- data/README.md +272 -0
- data/Rakefile +26 -0
- data/build_native_gems.sh +7 -0
- data/cucumber.yml +4 -0
- data/examples/parse_and_output_json.rb +19 -0
- data/features/.cucumber/stepdefs.json +244 -0
- data/features/escaped_pipes.feature +8 -0
- data/features/feature_parser.feature +237 -0
- data/features/json_formatter.feature +498 -0
- data/features/json_parser.feature +331 -0
- data/features/native_lexer.feature +19 -0
- data/features/parser_with_native_lexer.feature +205 -0
- data/features/pretty_formatter.feature +16 -0
- data/features/step_definitions/eyeball_steps.rb +3 -0
- data/features/step_definitions/gherkin_steps.rb +29 -0
- data/features/step_definitions/json_formatter_steps.rb +30 -0
- data/features/step_definitions/json_parser_steps.rb +20 -0
- data/features/step_definitions/pretty_formatter_steps.rb +85 -0
- data/features/steps_parser.feature +46 -0
- data/features/support/env.rb +42 -0
- data/gherkin.gemspec +77 -0
- data/install_mingw_os_x.sh +7 -0
- data/js/.npmignore +1 -0
- data/js/lib/gherkin/lexer/.npmignore +0 -0
- data/lib/gherkin/c_lexer.rb +17 -0
- data/lib/gherkin/formatter/ansi_escapes.rb +97 -0
- data/lib/gherkin/formatter/argument.rb +16 -0
- data/lib/gherkin/formatter/escaping.rb +15 -0
- data/lib/gherkin/formatter/filter_formatter.rb +146 -0
- data/lib/gherkin/formatter/hashable.rb +19 -0
- data/lib/gherkin/formatter/json_formatter.rb +122 -0
- data/lib/gherkin/formatter/line_filter.rb +26 -0
- data/lib/gherkin/formatter/model.rb +281 -0
- data/lib/gherkin/formatter/pretty_formatter.rb +244 -0
- data/lib/gherkin/formatter/regexp_filter.rb +21 -0
- data/lib/gherkin/formatter/step_printer.rb +21 -0
- data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
- data/lib/gherkin/formatter/tag_filter.rb +19 -0
- data/lib/gherkin/i18n.rb +180 -0
- data/lib/gherkin/i18n.yml +613 -0
- data/lib/gherkin/js_lexer.rb +20 -0
- data/lib/gherkin/json_parser.rb +177 -0
- data/lib/gherkin/lexer/i18n_lexer.rb +46 -0
- data/lib/gherkin/listener/event.rb +45 -0
- data/lib/gherkin/listener/formatter_listener.rb +143 -0
- data/lib/gherkin/native/java.rb +72 -0
- data/lib/gherkin/native/null.rb +5 -0
- data/lib/gherkin/native/therubyracer.rb +39 -0
- data/lib/gherkin/native.rb +7 -0
- data/lib/gherkin/parser/meta.txt +5 -0
- data/lib/gherkin/parser/parser.rb +164 -0
- data/lib/gherkin/parser/root.txt +11 -0
- data/lib/gherkin/parser/steps.txt +4 -0
- data/lib/gherkin/rb_lexer/README.rdoc +8 -0
- data/lib/gherkin/rb_lexer.rb +8 -0
- data/lib/gherkin/rubify.rb +24 -0
- data/lib/gherkin/tag_expression.rb +62 -0
- data/lib/gherkin.jar +0 -0
- data/lib/gherkin.rb +2 -0
- data/ragel/lexer.c.rl.erb +454 -0
- data/ragel/lexer.java.rl.erb +219 -0
- data/ragel/lexer.js.rl.erb +227 -0
- data/ragel/lexer.rb.rl.erb +174 -0
- data/ragel/lexer_common.rl.erb +50 -0
- data/spec/gherkin/c_lexer_spec.rb +22 -0
- data/spec/gherkin/fixtures/1.feature +8 -0
- data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
- data/spec/gherkin/fixtures/complex.feature +45 -0
- data/spec/gherkin/fixtures/complex.json +139 -0
- data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
- data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
- data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
- data/spec/gherkin/fixtures/examples_with_only_header.feature +14 -0
- data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
- data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
- data/spec/gherkin/fixtures/i18n_fr2.feature +8 -0
- data/spec/gherkin/fixtures/i18n_no.feature +7 -0
- data/spec/gherkin/fixtures/i18n_pt1.feature +44 -0
- data/spec/gherkin/fixtures/i18n_pt2.feature +4 -0
- data/spec/gherkin/fixtures/i18n_pt3.feature +4 -0
- data/spec/gherkin/fixtures/i18n_pt4.feature +4 -0
- data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
- data/spec/gherkin/fixtures/issue_145.feature +22 -0
- data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
- data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
- data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
- data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
- data/spec/gherkin/fixtures/with_bom.feature +3 -0
- data/spec/gherkin/formatter/ansi_escapes_spec.rb +32 -0
- data/spec/gherkin/formatter/filter_formatter_spec.rb +204 -0
- data/spec/gherkin/formatter/json_formatter_spec.rb +92 -0
- data/spec/gherkin/formatter/model_spec.rb +28 -0
- data/spec/gherkin/formatter/pretty_formatter_spec.rb +177 -0
- data/spec/gherkin/formatter/spaces.feature +9 -0
- data/spec/gherkin/formatter/step_printer_spec.rb +55 -0
- data/spec/gherkin/formatter/tabs.feature +9 -0
- data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
- data/spec/gherkin/i18n_spec.rb +241 -0
- data/spec/gherkin/java_lexer_spec.rb +20 -0
- data/spec/gherkin/js_lexer_spec.rb +23 -0
- data/spec/gherkin/json_parser_spec.rb +176 -0
- data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
- data/spec/gherkin/output_stream_string_io.rb +20 -0
- data/spec/gherkin/parser/parser_spec.rb +16 -0
- data/spec/gherkin/rb_lexer_spec.rb +20 -0
- data/spec/gherkin/sexp_recorder.rb +59 -0
- data/spec/gherkin/shared/bom_group.rb +20 -0
- data/spec/gherkin/shared/doc_string_group.rb +163 -0
- data/spec/gherkin/shared/lexer_group.rb +591 -0
- data/spec/gherkin/shared/row_group.rb +125 -0
- data/spec/gherkin/shared/tags_group.rb +54 -0
- data/spec/gherkin/tag_expression_spec.rb +142 -0
- data/spec/spec_helper.rb +75 -0
- data/tasks/bench/feature_builder.rb +49 -0
- data/tasks/bench/null_listener.rb +4 -0
- data/tasks/bench.rake +184 -0
- data/tasks/compile.rake +120 -0
- data/tasks/cucumber.rake +22 -0
- data/tasks/gems.rake +31 -0
- data/tasks/ikvm.rake +124 -0
- data/tasks/ragel_task.rb +100 -0
- data/tasks/release.rake +49 -0
- data/tasks/rspec.rake +8 -0
- data/tasks/yard/default/layout/html/bubble_32x32.png +0 -0
- data/tasks/yard/default/layout/html/bubble_48x48.png +0 -0
- data/tasks/yard/default/layout/html/footer.erb +5 -0
- data/tasks/yard/default/layout/html/index.erb +1 -0
- data/tasks/yard/default/layout/html/layout.erb +25 -0
- data/tasks/yard/default/layout/html/logo.erb +1 -0
- data/tasks/yard/default/layout/html/setup.rb +4 -0
- data/tasks/yard.rake +7 -0
- metadata +412 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'stringio'
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'gherkin/parser/parser'
|
|
5
|
+
require 'gherkin/formatter/filter_formatter'
|
|
6
|
+
require 'gherkin/formatter/pretty_formatter'
|
|
7
|
+
|
|
8
|
+
module Gherkin
|
|
9
|
+
module Formatter
|
|
10
|
+
describe FilterFormatter do
|
|
11
|
+
attr_accessor :file
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
self.file = 'complex_for_filtering.feature'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def verify_filter(filters, *line_ranges)
|
|
18
|
+
io = StringIO.new
|
|
19
|
+
pretty_formatter = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
|
|
20
|
+
filter_formatter = Gherkin::Formatter::FilterFormatter.new(pretty_formatter, filters)
|
|
21
|
+
parser = Gherkin::Parser::Parser.new(filter_formatter)
|
|
22
|
+
|
|
23
|
+
path = File.dirname(__FILE__) + "/../fixtures/" + file
|
|
24
|
+
source = File.new(path).read + "# __EOF__"
|
|
25
|
+
parser.parse(source, path, 0)
|
|
26
|
+
|
|
27
|
+
source_lines = source.split("\n")
|
|
28
|
+
expected = (line_ranges.map do |line_range|
|
|
29
|
+
source_lines[(line_range.first-1..line_range.last-1)]
|
|
30
|
+
end.flatten).join("\n").gsub(/# __EOF__/, '')
|
|
31
|
+
io.string.strip.should == expected.strip
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "invalid mix" do
|
|
35
|
+
it "should throw exception on different filters" do
|
|
36
|
+
lambda do
|
|
37
|
+
verify_filter(['@tag1', /regexp/, 88], 1..61)
|
|
38
|
+
end.should raise_exception(/Inconsistent filters/)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "tags" do
|
|
43
|
+
it "should filter on feature tag" do
|
|
44
|
+
verify_filter(['@tag1'], 1..61)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "should filter on scenario tag" do
|
|
48
|
+
verify_filter(['@tag4'], 1..19)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should filter on abother scenario tag" do
|
|
52
|
+
verify_filter(['@tag3'], 1..37)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should filter on scenario outline tag" do
|
|
56
|
+
verify_filter(['@more'], 1..14, 46..61)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should filter on first examples tag" do
|
|
60
|
+
verify_filter(['@neat'], 1..14, 46..55)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should filter on second examples tag" do
|
|
64
|
+
verify_filter(['@hamster'], 1..14, 46..49, 56..61)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should not replay examples from ignored scenario outline" do
|
|
68
|
+
self.file = 'scenario_outline_with_tags.feature'
|
|
69
|
+
verify_filter(['~@wip'], 1..2, 12..14)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should not replay examples from ignored scenario outline" do
|
|
73
|
+
self.file = 'scenario_outline_with_tags.feature'
|
|
74
|
+
verify_filter(['~@wip'], 1..2, 12..14)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should not choke on examples with only header" do
|
|
78
|
+
self.file = 'examples_with_only_header.feature'
|
|
79
|
+
verify_filter(['@failing'], 1..7, 12..15)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "names" do
|
|
84
|
+
it "should filter on scenario name" do
|
|
85
|
+
verify_filter([/Reading a Scenario/], 1..19)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should filter on scenario outline name" do
|
|
89
|
+
verify_filter([/More/], 1..14, 46..61)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should filter on first examples name" do
|
|
93
|
+
verify_filter([/Neato/], 1..14, 46..55)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "should filter on second examples name" do
|
|
97
|
+
verify_filter([/Rodents/], 1..14, 46..49, 56..61)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should filter on various names" do
|
|
101
|
+
self.file = 'hantu_pisang.feature'
|
|
102
|
+
verify_filter([/Pisang/], 1..8, 19..32)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should filter on background name" do
|
|
106
|
+
self.file = 'hantu_pisang.feature'
|
|
107
|
+
verify_filter([/The background/], 1..5)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should not choke on examples with only header" do
|
|
111
|
+
self.file = 'examples_with_only_header.feature'
|
|
112
|
+
verify_filter([/B/], 1..7, 12..15)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
context "lines" do
|
|
117
|
+
context "on the same line as feature element keyword" do
|
|
118
|
+
it "should filter on scenario without line" do
|
|
119
|
+
self.file = 'scenario_without_steps.feature'
|
|
120
|
+
verify_filter([3], 1..4)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "should filter on scenario line" do
|
|
124
|
+
verify_filter([16], 1..19)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should filter on scenario outline line" do
|
|
128
|
+
verify_filter([47], 1..14, 46..61)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "should filter on first examples line" do
|
|
132
|
+
verify_filter([51], 1..14, 46..55)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should filter on second examples line" do
|
|
136
|
+
verify_filter([57], 1..14, 46..49, 56..61)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "should not choke on examples with only header" do
|
|
140
|
+
self.file = 'examples_with_only_header.feature'
|
|
141
|
+
verify_filter([13], 1..7, 12..15)
|
|
142
|
+
verify_filter([14], 1..7, 12..15)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "should fix issue 145" do
|
|
146
|
+
self.file = 'issue_145.feature'
|
|
147
|
+
verify_filter([14], 1..2, 6..12, 14..14)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "should fix issue 145 more tests" do
|
|
151
|
+
self.file = 'issue_145.feature'
|
|
152
|
+
verify_filter([13,15,18], 1..2, 6..13, 15..15, 16..18)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context "on the same line as step keyword" do
|
|
157
|
+
it "should filter on step line" do
|
|
158
|
+
verify_filter([17], 1..19)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "should filter on scenario outline line" do
|
|
162
|
+
verify_filter([48], 1..14, 46..61)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context "on examples header line" do
|
|
167
|
+
it "should filter on first table" do
|
|
168
|
+
verify_filter([52], 1..14, 46..55)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it "should filter on second table" do
|
|
172
|
+
verify_filter([58], 1..14, 46..49, 56..61)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
context "on examples example line" do
|
|
177
|
+
it "should filter on first table" do
|
|
178
|
+
verify_filter([53], 1..14, 46..53, 55..55)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
context "on tag line" do
|
|
183
|
+
it "should filter on first tag" do
|
|
184
|
+
verify_filter([15], 1..19)
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
context "multiline argument" do
|
|
189
|
+
it "should filter on table line" do
|
|
190
|
+
verify_filter([36], 1..14, 20..37)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "should filter on first pystring quote" do
|
|
194
|
+
verify_filter([41], 1..14, 38..45)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "should filter on last pystring quote" do
|
|
198
|
+
verify_filter([44], 1..14, 38..45)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stringio'
|
|
3
|
+
require 'gherkin/formatter/json_formatter'
|
|
4
|
+
require 'gherkin/formatter/model'
|
|
5
|
+
|
|
6
|
+
module Gherkin
|
|
7
|
+
module Formatter
|
|
8
|
+
describe JSONFormatter do
|
|
9
|
+
it "renders results" do
|
|
10
|
+
io = StringIO.new
|
|
11
|
+
f = JSONFormatter.new(io)
|
|
12
|
+
f.uri("f.feature")
|
|
13
|
+
f.feature(Model::Feature.new([], [], "Feature", "ff", "", 1, "ff"))
|
|
14
|
+
f.scenario(Model::Scenario.new([], [], "Scenario", "ss", "", 2, "ff/ss"))
|
|
15
|
+
|
|
16
|
+
f.step(Model::Step.new([], "Given ", "g", 3, nil, nil))
|
|
17
|
+
f.match(Model::Match.new([], "def.rb:33"))
|
|
18
|
+
f.result(Model::Result.new(:passed, 1, nil))
|
|
19
|
+
|
|
20
|
+
f.step(Model::Step.new([], "When ", "w", 4, nil, nil))
|
|
21
|
+
f.match(Model::Match.new([], "def.rb:44"))
|
|
22
|
+
f.result(Model::Result.new(:passed, 1, nil))
|
|
23
|
+
|
|
24
|
+
f.after(Model::Match.new([], "def.rb:55"), Model::Result.new(:passed, 22, nil))
|
|
25
|
+
|
|
26
|
+
f.eof
|
|
27
|
+
f.done
|
|
28
|
+
|
|
29
|
+
expected = %{
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
"id": "ff",
|
|
33
|
+
"uri": "f.feature",
|
|
34
|
+
"keyword": "Feature",
|
|
35
|
+
"name": "ff",
|
|
36
|
+
"line": 1,
|
|
37
|
+
"description": "",
|
|
38
|
+
"elements": [
|
|
39
|
+
{
|
|
40
|
+
"id": "ff/ss",
|
|
41
|
+
"keyword": "Scenario",
|
|
42
|
+
"name": "ss",
|
|
43
|
+
"line": 2,
|
|
44
|
+
"description": "",
|
|
45
|
+
"type": "scenario",
|
|
46
|
+
"steps": [
|
|
47
|
+
{
|
|
48
|
+
"keyword": "Given ",
|
|
49
|
+
"name": "g",
|
|
50
|
+
"line": 3,
|
|
51
|
+
"match": {
|
|
52
|
+
"location": "def.rb:33"
|
|
53
|
+
},
|
|
54
|
+
"result": {
|
|
55
|
+
"status": "passed",
|
|
56
|
+
"duration": 1
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"keyword": "When ",
|
|
61
|
+
"name": "w",
|
|
62
|
+
"line": 4,
|
|
63
|
+
"match": {
|
|
64
|
+
"location": "def.rb:44"
|
|
65
|
+
},
|
|
66
|
+
"result": {
|
|
67
|
+
"status": "passed",
|
|
68
|
+
"duration": 1
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"after": [
|
|
73
|
+
{
|
|
74
|
+
"match":{
|
|
75
|
+
"location":"def.rb:55"
|
|
76
|
+
},
|
|
77
|
+
"result":{
|
|
78
|
+
"status":"passed",
|
|
79
|
+
"duration": 22
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
JSON.parse(expected).should == JSON.parse(io.string)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'gherkin/formatter/model'
|
|
3
|
+
require 'gherkin/formatter/argument'
|
|
4
|
+
|
|
5
|
+
module Gherkin
|
|
6
|
+
module Formatter
|
|
7
|
+
module Model
|
|
8
|
+
describe Tag do
|
|
9
|
+
it "should be equal when name is equal" do
|
|
10
|
+
tags = [Tag.new('@x', 1), Tag.new('@y', 2), Tag.new('@x', 3)]
|
|
11
|
+
tags.to_a.uniq.length.should == 2
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe Step do
|
|
16
|
+
it "should provide arguments for outline tokens" do
|
|
17
|
+
step = Step.new([], 'Given ', "I have <number> cukes in <whose> belly", 10, nil, nil)
|
|
18
|
+
step.outline_args.map{|arg| [arg.offset, arg.val]}.should == [[7, "<number>"], [25, "<whose>"]]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should provide no arguments when there are no outline tokens" do
|
|
22
|
+
step = Step.new([], 'Given ', "I have 33 cukes in my belly", 10, nil, nil)
|
|
23
|
+
step.outline_args.to_a.should == []
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'gherkin/formatter/pretty_formatter'
|
|
4
|
+
require 'gherkin/formatter/argument'
|
|
5
|
+
require 'gherkin/formatter/model'
|
|
6
|
+
require 'gherkin/listener/formatter_listener'
|
|
7
|
+
require 'gherkin/parser/parser'
|
|
8
|
+
require 'stringio'
|
|
9
|
+
|
|
10
|
+
module Gherkin
|
|
11
|
+
module Formatter
|
|
12
|
+
describe PrettyFormatter do
|
|
13
|
+
include AnsiEscapes
|
|
14
|
+
|
|
15
|
+
def assert_io(s)
|
|
16
|
+
actual = @io.string
|
|
17
|
+
actual.gsub!(/\e\[m/, "\e[0m") # JANSI resets without the 0.
|
|
18
|
+
actual.should == s
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def assert_pretty(input, expected_output=input)
|
|
22
|
+
[true, false].each do |force_ruby|
|
|
23
|
+
io = StringIO.new
|
|
24
|
+
pf = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
|
|
25
|
+
parser = Gherkin::Parser::Parser.new(pf, true, "root", force_ruby)
|
|
26
|
+
parser.parse(input, "test.feature", 0)
|
|
27
|
+
output = io.string
|
|
28
|
+
output.should == expected_output
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
before do
|
|
33
|
+
@io = StringIO.new
|
|
34
|
+
@f = Gherkin::Formatter::PrettyFormatter.new(@io, false, true)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should print comments when scenario is longer" do
|
|
38
|
+
@f.uri("features/foo.feature")
|
|
39
|
+
@f.feature(Model::Feature.new([], [], "Feature", "Hello", "World", 1, "hello"))
|
|
40
|
+
|
|
41
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "The scenario", "", 4, "the-scenario"))
|
|
42
|
+
@f.step(Model::Step.new([], "Given ", "some stuff", 5, nil, nil))
|
|
43
|
+
@f.step(Model::Step.new([], "When ", "foo", 6, nil, nil))
|
|
44
|
+
|
|
45
|
+
@f.match(Model::Match.new([], "features/step_definitions/bar.rb:56"))
|
|
46
|
+
@f.result(Model::Result.new('passed', 22, nil))
|
|
47
|
+
|
|
48
|
+
@f.match(Model::Match.new([], "features/step_definitions/bar.rb:96"))
|
|
49
|
+
@f.result(Model::Result.new('passed', 33, nil))
|
|
50
|
+
|
|
51
|
+
assert_io(%{Feature: Hello
|
|
52
|
+
World
|
|
53
|
+
|
|
54
|
+
Scenario: The scenario #{comments}# features/foo.feature:4#{reset}
|
|
55
|
+
#{executing}Given #{reset}#{executing}some stuff#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
|
56
|
+
#{up(1)} #{passed}Given #{reset}#{passed}some stuff#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
|
57
|
+
#{executing}When #{reset}#{executing}foo#{reset} #{comments}# features/step_definitions/bar.rb:96#{reset}
|
|
58
|
+
#{up(1)} #{passed}When #{reset}#{passed}foo#{reset} #{comments}# features/step_definitions/bar.rb:96#{reset}
|
|
59
|
+
})
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should print comments when step is longer" do
|
|
63
|
+
@f.uri("features/foo.feature")
|
|
64
|
+
@f.feature(Model::Feature.new([], [], "Feature", "Hello", "World", 1, "hello"))
|
|
65
|
+
step = Model::Step.new([], "Given ", "some stuff that is longer", 5, nil, nil)
|
|
66
|
+
match = Model::Match.new([], "features/step_definitions/bar.rb:56")
|
|
67
|
+
result = Model::Result.new('passed', 0, nil)
|
|
68
|
+
|
|
69
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "The scenario", "", 4, "the-scenario"))
|
|
70
|
+
@f.step(step)
|
|
71
|
+
@f.match(match)
|
|
72
|
+
@f.result(result)
|
|
73
|
+
|
|
74
|
+
assert_io(%{Feature: Hello
|
|
75
|
+
World
|
|
76
|
+
|
|
77
|
+
Scenario: The scenario #{comments}# features/foo.feature:4#{reset}
|
|
78
|
+
#{executing}Given #{reset}#{executing}some stuff that is longer#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
|
79
|
+
#{up(1)} #{passed}Given #{reset}#{passed}some stuff that is longer#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
|
80
|
+
})
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should highlight arguments for regular steps" do
|
|
84
|
+
@f.uri("foo.feature")
|
|
85
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "Lots of cukes", "", 3, "lots-of-cukes"))
|
|
86
|
+
@f.step(Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3, nil, nil))
|
|
87
|
+
@f.match(Model::Match.new([Gherkin::Formatter::Argument.new(7, '999')], nil))
|
|
88
|
+
@f.result(Model::Result.new('passed', 6, nil))
|
|
89
|
+
|
|
90
|
+
assert_io(
|
|
91
|
+
"\n" +
|
|
92
|
+
" Scenario: Lots of cukes \e[90m# foo.feature:3\e[0m\n" +
|
|
93
|
+
" #{executing}Given #{reset}#{executing}I have #{reset}#{executing_arg}999#{reset}#{executing} cukes in my belly#{reset}\n" +
|
|
94
|
+
"#{up(1)} #{passed}Given #{reset}#{passed}I have #{reset}#{passed_arg}999#{reset}#{passed} cukes in my belly#{reset}\n"
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# See https://github.com/cucumber/gherkin/pull/171
|
|
99
|
+
it "should highlight arguments when there are optional arguments" do
|
|
100
|
+
@f.uri("foo.feature")
|
|
101
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "Lots of cukes", "", 3, "lots-of-cukes"))
|
|
102
|
+
@f.step(Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3, nil, nil))
|
|
103
|
+
@f.match(Model::Match.new([
|
|
104
|
+
Gherkin::Formatter::Argument.new(nil, nil), # An optional argument
|
|
105
|
+
Gherkin::Formatter::Argument.new(7, '999')
|
|
106
|
+
], nil))
|
|
107
|
+
@f.result(Model::Result.new('passed', 6, nil))
|
|
108
|
+
|
|
109
|
+
assert_io(
|
|
110
|
+
"\n" +
|
|
111
|
+
" Scenario: Lots of cukes \e[90m# foo.feature:3\e[0m\n" +
|
|
112
|
+
" #{executing}Given #{reset}#{executing}I have #{reset}#{executing_arg}999#{reset}#{executing} cukes in my belly#{reset}\n" +
|
|
113
|
+
"#{up(1)} #{passed}Given #{reset}#{passed}I have #{reset}#{passed_arg}999#{reset}#{passed} cukes in my belly#{reset}\n"
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should prettify scenario" do
|
|
118
|
+
assert_pretty(%{Feature: Feature Description
|
|
119
|
+
Some preamble
|
|
120
|
+
|
|
121
|
+
Scenario: Scenario Description
|
|
122
|
+
description has multiple lines
|
|
123
|
+
|
|
124
|
+
Given there is a step
|
|
125
|
+
"""
|
|
126
|
+
with
|
|
127
|
+
pystrings
|
|
128
|
+
"""
|
|
129
|
+
And there is another step
|
|
130
|
+
| æ | \\|o |
|
|
131
|
+
| \\|a | ø\\\\ |
|
|
132
|
+
Then we will see steps
|
|
133
|
+
})
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
it "should prettify scenario outline with table" do
|
|
138
|
+
assert_pretty(%{# A feature comment
|
|
139
|
+
@foo
|
|
140
|
+
Feature: Feature Description
|
|
141
|
+
Some preamble
|
|
142
|
+
on several
|
|
143
|
+
lines
|
|
144
|
+
|
|
145
|
+
# A Scenario Outline comment
|
|
146
|
+
@bar
|
|
147
|
+
Scenario Outline: Scenario Ouline Description
|
|
148
|
+
Given there is a
|
|
149
|
+
"""
|
|
150
|
+
string with <foo>
|
|
151
|
+
"""
|
|
152
|
+
And a table with
|
|
153
|
+
| <bar> |
|
|
154
|
+
| <baz> |
|
|
155
|
+
|
|
156
|
+
@zap @boing
|
|
157
|
+
Examples: Examples Description
|
|
158
|
+
| foo | bar | baz |
|
|
159
|
+
| Banana | I | am hungry |
|
|
160
|
+
| Beer | You | are thirsty |
|
|
161
|
+
| Bed | They | are tired |
|
|
162
|
+
})
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "should preserve tabs" do
|
|
166
|
+
assert_pretty(IO.read(File.dirname(__FILE__) + '/tabs.feature'), IO.read(File.dirname(__FILE__) + '/spaces.feature'))
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "should escape backslashes and pipes" do
|
|
170
|
+
io = StringIO.new
|
|
171
|
+
f = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
|
|
172
|
+
f.__send__(:table, [Gherkin::Formatter::Model::DataTableRow.new([], ['|', '\\'], 1)])
|
|
173
|
+
io.string.should == ' | \\| | \\\\ |' + "\n"
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'gherkin/formatter/step_printer'
|
|
4
|
+
require 'gherkin/formatter/argument'
|
|
5
|
+
require 'stringio'
|
|
6
|
+
|
|
7
|
+
module Gherkin
|
|
8
|
+
module Formatter
|
|
9
|
+
class ParenthesisFormat
|
|
10
|
+
def text(text)
|
|
11
|
+
"(#{text})"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class BracketFormat
|
|
16
|
+
def text(text)
|
|
17
|
+
"[#{text}]"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe StepPrinter do
|
|
22
|
+
before do
|
|
23
|
+
@io = StringIO.new
|
|
24
|
+
@p = StepPrinter.new
|
|
25
|
+
@pf = ParenthesisFormat.new
|
|
26
|
+
@bf = BracketFormat.new
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should replace 0 args" do
|
|
30
|
+
@p.write_step(@io, @pf, @bf, "I have 10 cukes", [])
|
|
31
|
+
@io.string.should == "(I have 10 cukes)"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should replace 1 arg" do
|
|
35
|
+
@p.write_step(@io, @pf, @bf, "I have 10 cukes", [Argument.new(7, '10')])
|
|
36
|
+
@io.string.should == "(I have )[10]( cukes)"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should replace 1 unicode arg" do
|
|
40
|
+
@p.write_step(@io, @pf, @bf, "I hæve øæ cåkes", [Argument.new(7, 'øæ')])
|
|
41
|
+
@io.string.should == "(I hæve )[øæ]( cåkes)"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should replace 2 args" do
|
|
45
|
+
@p.write_step(@io, @pf, @bf, "I have 10 yellow cukes in my belly", [Argument.new(7, '10'), Argument.new(17, 'cukes')])
|
|
46
|
+
@io.string.should == "(I have )[10]( yellow )[cukes]( in my belly)"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should replace 2 unicode args" do
|
|
50
|
+
@p.write_step(@io, @pf, @bf, "Æslåk likes æøå", [Argument.new(0, 'Æslåk'), Argument.new(12, 'æøå')])
|
|
51
|
+
@io.string.should == "[Æslåk]( likes )[æøå]"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'gherkin/parser/parser'
|
|
4
|
+
require 'gherkin/formatter/tag_count_formatter'
|
|
5
|
+
|
|
6
|
+
module Gherkin
|
|
7
|
+
module Formatter
|
|
8
|
+
describe TagCountFormatter do
|
|
9
|
+
it "should count tags" do
|
|
10
|
+
tag_counts = {}
|
|
11
|
+
dummy = Gherkin::SexpRecorder.new
|
|
12
|
+
formatter = Gherkin::Formatter::TagCountFormatter.new(dummy, tag_counts)
|
|
13
|
+
parser = Gherkin::Parser::Parser.new(formatter)
|
|
14
|
+
|
|
15
|
+
f = File.new(File.dirname(__FILE__) + "/../fixtures/complex_with_tags.feature").read
|
|
16
|
+
parser.parse(f, 'f.feature', 0)
|
|
17
|
+
|
|
18
|
+
tag_counts.should == {
|
|
19
|
+
"@hamster" => ["f.feature:58"],
|
|
20
|
+
"@tag1" => ["f.feature:18","f.feature:23","f.feature:39","f.feature:52","f.feature:58"],
|
|
21
|
+
"@tag2" => ["f.feature:18","f.feature:23","f.feature:39","f.feature:52","f.feature:58"],
|
|
22
|
+
"@tag3" => ["f.feature:18", "f.feature:23"],
|
|
23
|
+
"@tag4" => ["f.feature:18"],
|
|
24
|
+
"@neat" => ["f.feature:52"],
|
|
25
|
+
"@more" => ["f.feature:52", "f.feature:58"]
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|