benhamill-gherkin 2.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitattributes +2 -0
  2. data/.gitignore +11 -0
  3. data/.mailmap +2 -0
  4. data/.rspec +1 -0
  5. data/.rvmrc +1 -0
  6. data/Gemfile +7 -0
  7. data/History.txt +363 -0
  8. data/LICENSE +20 -0
  9. data/README.rdoc +149 -0
  10. data/Rakefile +19 -0
  11. data/VERSION +1 -0
  12. data/build_native_gems.sh +8 -0
  13. data/cucumber.yml +3 -0
  14. data/features/escaped_pipes.feature +8 -0
  15. data/features/feature_parser.feature +237 -0
  16. data/features/json_formatter.feature +377 -0
  17. data/features/json_parser.feature +318 -0
  18. data/features/native_lexer.feature +19 -0
  19. data/features/parser_with_native_lexer.feature +205 -0
  20. data/features/pretty_formatter.feature +15 -0
  21. data/features/step_definitions/eyeball_steps.rb +3 -0
  22. data/features/step_definitions/gherkin_steps.rb +29 -0
  23. data/features/step_definitions/json_formatter_steps.rb +28 -0
  24. data/features/step_definitions/json_parser_steps.rb +20 -0
  25. data/features/step_definitions/pretty_formatter_steps.rb +84 -0
  26. data/features/steps_parser.feature +46 -0
  27. data/features/support/env.rb +38 -0
  28. data/gherkin.gemspec +61 -0
  29. data/ikvm/.gitignore +3 -0
  30. data/java/.gitignore +5 -0
  31. data/java/src/main/java/gherkin/lexer/i18n/.gitignore +1 -0
  32. data/java/src/main/resources/gherkin/.gitignore +1 -0
  33. data/js/lib/gherkin/lexer/i18n/ar.js +1094 -0
  34. data/js/lib/gherkin/lexer/i18n/bg.js +1308 -0
  35. data/js/lib/gherkin/lexer/i18n/ca.js +1236 -0
  36. data/js/lib/gherkin/lexer/i18n/cs.js +1090 -0
  37. data/js/lib/gherkin/lexer/i18n/cy_gb.js +958 -0
  38. data/js/lib/gherkin/lexer/i18n/da.js +974 -0
  39. data/js/lib/gherkin/lexer/i18n/de.js +1082 -0
  40. data/js/lib/gherkin/lexer/i18n/en.js +965 -0
  41. data/js/lib/gherkin/lexer/i18n/en_au.js +902 -0
  42. data/js/lib/gherkin/lexer/i18n/en_lol.js +859 -0
  43. data/js/lib/gherkin/lexer/i18n/en_pirate.js +1136 -0
  44. data/js/lib/gherkin/lexer/i18n/en_scouse.js +1289 -0
  45. data/js/lib/gherkin/lexer/i18n/en_tx.js +942 -0
  46. data/js/lib/gherkin/lexer/i18n/eo.js +916 -0
  47. data/js/lib/gherkin/lexer/i18n/es.js +1049 -0
  48. data/js/lib/gherkin/lexer/i18n/et.js +915 -0
  49. data/js/lib/gherkin/lexer/i18n/fi.js +894 -0
  50. data/js/lib/gherkin/lexer/i18n/fr.js +1116 -0
  51. data/js/lib/gherkin/lexer/i18n/he.js +1044 -0
  52. data/js/lib/gherkin/lexer/i18n/hr.js +994 -0
  53. data/js/lib/gherkin/lexer/i18n/hu.js +1043 -0
  54. data/js/lib/gherkin/lexer/i18n/id.js +884 -0
  55. data/js/lib/gherkin/lexer/i18n/it.js +1007 -0
  56. data/js/lib/gherkin/lexer/i18n/ja.js +1344 -0
  57. data/js/lib/gherkin/lexer/i18n/ko.js +1028 -0
  58. data/js/lib/gherkin/lexer/i18n/lt.js +972 -0
  59. data/js/lib/gherkin/lexer/i18n/lu.js +1057 -0
  60. data/js/lib/gherkin/lexer/i18n/lv.js +1092 -0
  61. data/js/lib/gherkin/lexer/i18n/nl.js +1036 -0
  62. data/js/lib/gherkin/lexer/i18n/no.js +986 -0
  63. data/js/lib/gherkin/lexer/i18n/pl.js +1140 -0
  64. data/js/lib/gherkin/lexer/i18n/pt.js +1000 -0
  65. data/js/lib/gherkin/lexer/i18n/ro.js +1089 -0
  66. data/js/lib/gherkin/lexer/i18n/ru.js +1560 -0
  67. data/js/lib/gherkin/lexer/i18n/sk.js +972 -0
  68. data/js/lib/gherkin/lexer/i18n/sr_cyrl.js +1728 -0
  69. data/js/lib/gherkin/lexer/i18n/sr_latn.js +1220 -0
  70. data/js/lib/gherkin/lexer/i18n/sv.js +997 -0
  71. data/js/lib/gherkin/lexer/i18n/tr.js +1014 -0
  72. data/js/lib/gherkin/lexer/i18n/uk.js +1572 -0
  73. data/js/lib/gherkin/lexer/i18n/uz.js +1302 -0
  74. data/js/lib/gherkin/lexer/i18n/vi.js +1124 -0
  75. data/js/lib/gherkin/lexer/i18n/zh_cn.js +902 -0
  76. data/js/lib/gherkin/lexer/i18n/zh_tw.js +940 -0
  77. data/lib/.gitignore +4 -0
  78. data/lib/gherkin.rb +2 -0
  79. data/lib/gherkin/c_lexer.rb +17 -0
  80. data/lib/gherkin/formatter/ansi_escapes.rb +95 -0
  81. data/lib/gherkin/formatter/argument.rb +16 -0
  82. data/lib/gherkin/formatter/escaping.rb +15 -0
  83. data/lib/gherkin/formatter/filter_formatter.rb +136 -0
  84. data/lib/gherkin/formatter/hashable.rb +19 -0
  85. data/lib/gherkin/formatter/json_formatter.rb +102 -0
  86. data/lib/gherkin/formatter/line_filter.rb +26 -0
  87. data/lib/gherkin/formatter/model.rb +236 -0
  88. data/lib/gherkin/formatter/pretty_formatter.rb +243 -0
  89. data/lib/gherkin/formatter/regexp_filter.rb +21 -0
  90. data/lib/gherkin/formatter/step_printer.rb +17 -0
  91. data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
  92. data/lib/gherkin/formatter/tag_filter.rb +19 -0
  93. data/lib/gherkin/i18n.rb +175 -0
  94. data/lib/gherkin/i18n.yml +588 -0
  95. data/lib/gherkin/json_parser.rb +137 -0
  96. data/lib/gherkin/lexer/i18n_lexer.rb +47 -0
  97. data/lib/gherkin/listener/event.rb +45 -0
  98. data/lib/gherkin/listener/formatter_listener.rb +113 -0
  99. data/lib/gherkin/native.rb +7 -0
  100. data/lib/gherkin/native/ikvm.rb +55 -0
  101. data/lib/gherkin/native/java.rb +55 -0
  102. data/lib/gherkin/native/null.rb +9 -0
  103. data/lib/gherkin/parser/meta.txt +5 -0
  104. data/lib/gherkin/parser/parser.rb +164 -0
  105. data/lib/gherkin/parser/root.txt +11 -0
  106. data/lib/gherkin/parser/steps.txt +4 -0
  107. data/lib/gherkin/rb_lexer.rb +8 -0
  108. data/lib/gherkin/rb_lexer/.gitignore +1 -0
  109. data/lib/gherkin/rb_lexer/README.rdoc +8 -0
  110. data/lib/gherkin/rubify.rb +24 -0
  111. data/lib/gherkin/tag_expression.rb +62 -0
  112. data/lib/gherkin/version.rb +3 -0
  113. data/ragel/i18n/.gitignore +1 -0
  114. data/ragel/lexer.c.rl.erb +439 -0
  115. data/ragel/lexer.java.rl.erb +208 -0
  116. data/ragel/lexer.rb.rl.erb +167 -0
  117. data/ragel/lexer_common.rl.erb +50 -0
  118. data/spec/gherkin/c_lexer_spec.rb +21 -0
  119. data/spec/gherkin/fixtures/1.feature +8 -0
  120. data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
  121. data/spec/gherkin/fixtures/complex.feature +45 -0
  122. data/spec/gherkin/fixtures/complex.json +143 -0
  123. data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
  124. data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
  125. data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
  126. data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
  127. data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
  128. data/spec/gherkin/fixtures/i18n_no.feature +7 -0
  129. data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
  130. data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
  131. data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
  132. data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
  133. data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
  134. data/spec/gherkin/fixtures/with_bom.feature +3 -0
  135. data/spec/gherkin/formatter/ansi_escapes_spec.rb +19 -0
  136. data/spec/gherkin/formatter/filter_formatter_spec.rb +165 -0
  137. data/spec/gherkin/formatter/model_spec.rb +28 -0
  138. data/spec/gherkin/formatter/pretty_formatter_spec.rb +158 -0
  139. data/spec/gherkin/formatter/spaces.feature +9 -0
  140. data/spec/gherkin/formatter/step_printer_spec.rb +55 -0
  141. data/spec/gherkin/formatter/tabs.feature +9 -0
  142. data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
  143. data/spec/gherkin/i18n_spec.rb +152 -0
  144. data/spec/gherkin/java_lexer_spec.rb +20 -0
  145. data/spec/gherkin/java_libs.rb +20 -0
  146. data/spec/gherkin/json_parser_spec.rb +113 -0
  147. data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
  148. data/spec/gherkin/output_stream_string_io.rb +20 -0
  149. data/spec/gherkin/parser/parser_spec.rb +16 -0
  150. data/spec/gherkin/rb_lexer_spec.rb +19 -0
  151. data/spec/gherkin/sexp_recorder.rb +56 -0
  152. data/spec/gherkin/shared/lexer_group.rb +593 -0
  153. data/spec/gherkin/shared/py_string_group.rb +153 -0
  154. data/spec/gherkin/shared/row_group.rb +125 -0
  155. data/spec/gherkin/shared/tags_group.rb +54 -0
  156. data/spec/gherkin/tag_expression_spec.rb +137 -0
  157. data/spec/spec_helper.rb +69 -0
  158. data/tasks/bench.rake +184 -0
  159. data/tasks/bench/feature_builder.rb +49 -0
  160. data/tasks/bench/generated/.gitignore +1 -0
  161. data/tasks/bench/null_listener.rb +4 -0
  162. data/tasks/compile.rake +102 -0
  163. data/tasks/cucumber.rake +20 -0
  164. data/tasks/gems.rake +35 -0
  165. data/tasks/ikvm.rake +79 -0
  166. data/tasks/ragel_task.rb +70 -0
  167. data/tasks/rdoc.rake +9 -0
  168. data/tasks/release.rake +30 -0
  169. data/tasks/rspec.rake +8 -0
  170. metadata +609 -0
@@ -0,0 +1,13 @@
1
+ Feature: Bug 67
2
+
3
+ @wip
4
+ Scenario Outline: WIP
5
+ When blah
6
+
7
+ Examples:
8
+ | a |
9
+ | b |
10
+ | c |
11
+
12
+ Scenario: Not WIP
13
+ When blah
@@ -0,0 +1,5 @@
1
+ Feature: f
2
+
3
+ Scenario: a
4
+
5
+ Scenario: b
@@ -0,0 +1,7 @@
1
+ # Here is a comment
2
+ Feature: Feature Text
3
+ # Here is another # comment
4
+ Scenario: Reading a Scenario
5
+ # Here is a third comment
6
+ Given there is a step
7
+ # Here is a fourth comment
@@ -0,0 +1,11 @@
1
+ # FC
2
+ @ft
3
+ Feature: hi
4
+
5
+ @st1 @st2
6
+ Scenario: First
7
+ Given Pepper
8
+
9
+ @st3
10
+ @st4 @ST5 @#^%&ST6**!
11
+ Scenario: Second
@@ -0,0 +1,3 @@
1
+ Feature: Feature Text
2
+ Scenario: Reading a Scenario
3
+ Given there is a step
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'gherkin/formatter/ansi_escapes'
3
+
4
+ module Gherkin
5
+ module Formatter
6
+ describe AnsiEscapes do
7
+ include Gherkin::Formatter::AnsiEscapes
8
+
9
+ it "failed should be red" do
10
+ failed.should == "\e[31m"
11
+ end
12
+
13
+ it "failed arg should be red bold" do
14
+ failed_arg.should == "\e[31m\e[1m"
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,165 @@
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.should == expected
32
+ end
33
+
34
+ context "tags" do
35
+ it "should filter on feature tag" do
36
+ verify_filter(['@tag1'], 1..61)
37
+ end
38
+
39
+ it "should filter on scenario tag" do
40
+ verify_filter(['@tag4'], 1..19)
41
+ end
42
+
43
+ it "should filter on abother scenario tag" do
44
+ verify_filter(['@tag3'], 1..37)
45
+ end
46
+
47
+ it "should filter on scenario outline tag" do
48
+ verify_filter(['@more'], 1..14, 46..61)
49
+ end
50
+
51
+ it "should filter on first examples tag" do
52
+ verify_filter(['@neat'], 1..14, 46..55)
53
+ end
54
+
55
+ it "should filter on second examples tag" do
56
+ verify_filter(['@hamster'], 1..14, 46..49, 56..61)
57
+ end
58
+
59
+ it "should not replay examples from ignored scenario outline" do
60
+ self.file = 'scenario_outline_with_tags.feature'
61
+ verify_filter(['~@wip'], 1..2, 12..14)
62
+ end
63
+ end
64
+
65
+ context "names" do
66
+ it "should filter on scenario name" do
67
+ verify_filter([/Reading a Scenario/], 1..19)
68
+ end
69
+
70
+ it "should filter on scenario outline name" do
71
+ verify_filter([/More/], 1..14, 46..61)
72
+ end
73
+
74
+ it "should filter on first examples name" do
75
+ verify_filter([/Neato/], 1..14, 46..55)
76
+ end
77
+
78
+ it "should filter on second examples name" do
79
+ verify_filter([/Rodents/], 1..14, 46..49, 56..61)
80
+ end
81
+
82
+ it "should filter on various names" do
83
+ self.file = 'hantu_pisang.feature'
84
+ verify_filter([/Pisang/], 1..8, 19..32)
85
+ end
86
+
87
+ it "should filter on background name" do
88
+ self.file = 'hantu_pisang.feature'
89
+ verify_filter([/The background/], 1..5)
90
+ end
91
+ end
92
+
93
+ context "lines" do
94
+ context "on the same line as feature element keyword" do
95
+ it "should filter on scenario without line" do
96
+ self.file = 'scenario_without_steps.feature'
97
+ verify_filter([3], 1..4)
98
+ end
99
+
100
+ it "should filter on scenario line" do
101
+ verify_filter([16], 1..19)
102
+ end
103
+
104
+ it "should filter on scenario outline line" do
105
+ verify_filter([47], 1..14, 46..61)
106
+ end
107
+
108
+ it "should filter on first examples line" do
109
+ verify_filter([51], 1..14, 46..55)
110
+ end
111
+
112
+ it "should filter on second examples line" do
113
+ verify_filter([57], 1..14, 46..49, 56..61)
114
+ end
115
+ end
116
+
117
+ context "on the same line as step keyword" do
118
+ it "should filter on step line" do
119
+ verify_filter([17], 1..19)
120
+ end
121
+
122
+ it "should filter on scenario outline line" do
123
+ verify_filter([48], 1..14, 46..61)
124
+ end
125
+ end
126
+
127
+ context "on examples header line" do
128
+ it "should filter on first table" do
129
+ verify_filter([52], 1..14, 46..55)
130
+ end
131
+
132
+ it "should filter on second table" do
133
+ verify_filter([58], 1..14, 46..49, 56..61)
134
+ end
135
+ end
136
+
137
+ context "on examples example line" do
138
+ it "should filter on first table" do
139
+ verify_filter([53], 1..14, 46..53, 55..55)
140
+ end
141
+ end
142
+
143
+ context "on tag line" do
144
+ it "should filter on first tag" do
145
+ verify_filter([15], 1..19)
146
+ end
147
+ end
148
+
149
+ context "multiline argument" do
150
+ it "should filter on table line" do
151
+ verify_filter([36], 1..14, 20..37)
152
+ end
153
+
154
+ it "should filter on first pystring quote" do
155
+ verify_filter([41], 1..14, 38..45)
156
+ end
157
+
158
+ it "should filter on last pystring quote" do
159
+ verify_filter([44], 1..14, 38..45)
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+ 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)
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)
23
+ step.outline_args.to_a.should == []
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,158 @@
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))
40
+
41
+ @f.scenario(Model::Scenario.new([], [], "Scenario", "The scenario", "", 4))
42
+ @f.step(Model::Step.new([], "Given ", "some stuff", 5))
43
+ @f.step(Model::Step.new([], "When ", "foo", 6))
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))
65
+ step = Model::Step.new([], "Given ", "some stuff that is longer", 5)
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))
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))
86
+ @f.step(Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3))
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
+ it "should prettify scenario" do
99
+ assert_pretty(%{Feature: Feature Description
100
+ Some preamble
101
+
102
+ Scenario: Scenario Description
103
+ description has multiple lines
104
+
105
+ Given there is a step
106
+ """
107
+ with
108
+ pystrings
109
+ """
110
+ And there is another step
111
+ | æ | \\|o |
112
+ | \\|a | ø\\\\ |
113
+ Then we will see steps
114
+ })
115
+ end
116
+
117
+
118
+ it "should prettify scenario outline with table" do
119
+ assert_pretty(%{# A feature comment
120
+ @foo
121
+ Feature: Feature Description
122
+ Some preamble
123
+ on several
124
+ lines
125
+
126
+ # A Scenario Outline comment
127
+ @bar
128
+ Scenario Outline: Scenario Ouline Description
129
+ Given there is a
130
+ """
131
+ string with <foo>
132
+ """
133
+ And a table with
134
+ | <bar> |
135
+ | <baz> |
136
+
137
+ @zap @boing
138
+ Examples: Examples Description
139
+ | foo | bar | baz |
140
+ | Banana | I | am hungry |
141
+ | Beer | You | are thirsty |
142
+ | Bed | They | are tired |
143
+ })
144
+ end
145
+
146
+ it "should preserve tabs" do
147
+ assert_pretty(IO.read(File.dirname(__FILE__) + '/tabs.feature'), IO.read(File.dirname(__FILE__) + '/spaces.feature'))
148
+ end
149
+
150
+ it "should escape backslashes and pipes" do
151
+ io = StringIO.new
152
+ f = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
153
+ f.__send__(:table, [Gherkin::Formatter::Model::Row.new([], ['|', '\\'], nil)])
154
+ io.string.should == ' | \\| | \\\\ |' + "\n"
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,9 @@
1
+ Feature: Adding
2
+
3
+ Scenario: Add two numbers
4
+ Given the following input:
5
+ """
6
+ hello
7
+ """
8
+ When the calculator is run
9
+ Then the output should be 4
@@ -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