cucumber 0.1.16 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (322) hide show
  1. data/History.txt +111 -5
  2. data/License.txt +1 -1
  3. data/Manifest.txt +141 -83
  4. data/Rakefile +1 -1
  5. data/bin/cucumber +2 -2
  6. data/config/hoe.rb +8 -2
  7. data/examples/cs/features/addition.feature +4 -5
  8. data/examples/cs/features/step_definitons/calculator_steps.rb +1 -5
  9. data/examples/i18n/README.textile +1 -1
  10. data/examples/i18n/Rakefile +5 -5
  11. data/examples/i18n/ar/features/addition.feature +10 -11
  12. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +1 -10
  13. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +1 -1
  14. data/examples/i18n/de/features/addition.feature +10 -11
  15. data/examples/i18n/de/features/division.feature +0 -1
  16. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +2 -10
  17. data/examples/i18n/en-lol/Rakefile +6 -0
  18. data/examples/i18n/en-lol/features/step_definitions/cucumbrz_steps.rb +16 -0
  19. data/examples/i18n/en-lol/features/stuffing.feature +8 -0
  20. data/examples/i18n/en-lol/features/support/env.rb +8 -0
  21. data/examples/i18n/en-lol/lib/basket.rb +12 -0
  22. data/examples/i18n/en-lol/lib/belly.rb +11 -0
  23. data/examples/i18n/en/features/addition.feature +10 -11
  24. data/examples/i18n/en/features/division.feature +0 -1
  25. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +2 -6
  26. data/examples/i18n/es/features/adicion.feature +11 -12
  27. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +7 -10
  28. data/examples/i18n/es/lib/calculador.rb +4 -1
  29. data/examples/i18n/et/features/jagamine.feature +9 -0
  30. data/examples/i18n/et/features/liitmine.feature +10 -11
  31. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +4 -8
  32. data/examples/i18n/et/lib/kalkulaator.rb +5 -1
  33. data/examples/i18n/fi/Rakefile +6 -0
  34. data/examples/i18n/fi/features/jakolasku.feature +9 -0
  35. data/examples/i18n/fi/features/step_definitons/laskin_steps.rb +24 -0
  36. data/examples/i18n/fi/features/yhteenlasku.feature +16 -0
  37. data/examples/i18n/fi/lib/laskin.rb +14 -0
  38. data/examples/i18n/fr/features/addition.feature +14 -12
  39. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +11 -13
  40. data/examples/i18n/fr/lib/calculatrice.rb +1 -1
  41. data/examples/i18n/id/features/addition.feature +10 -11
  42. data/examples/i18n/id/features/division.feature +0 -1
  43. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +2 -11
  44. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +1 -1
  45. data/examples/i18n/ja/features/addition.feature +10 -11
  46. data/examples/i18n/ja/features/division.feature +2 -3
  47. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +4 -13
  48. data/examples/i18n/ko/features/addition.feature +7 -8
  49. data/examples/i18n/ko/features/division.feature +3 -4
  50. data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +1 -5
  51. data/examples/i18n/lt/features/addition.feature +11 -11
  52. data/examples/i18n/lt/features/division.feature +0 -1
  53. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +2 -11
  54. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +3 -10
  55. data/examples/i18n/no/features/summering.feature +1 -0
  56. data/examples/i18n/no/features/support/env.rb +6 -0
  57. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +1 -1
  58. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +1 -1
  59. data/examples/i18n/ru/Rakefile +6 -0
  60. data/examples/i18n/ru/features/addition.feature +10 -0
  61. data/examples/i18n/ru/features/consecutive_calculations.feature +16 -0
  62. data/examples/i18n/ru/features/division.feature +15 -0
  63. data/examples/i18n/ru/features/step_definitons/calculator_steps.rb +19 -0
  64. data/examples/i18n/ru/features/support/env.rb +6 -0
  65. data/examples/i18n/ru/features/support/world.rb +7 -0
  66. data/examples/i18n/ru/lib/calculator.rb +24 -0
  67. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +1 -1
  68. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +2 -2
  69. data/examples/i18n/zh-TW/Rakefile +6 -0
  70. data/examples/i18n/zh-TW/features/addition.feature +16 -0
  71. data/examples/i18n/zh-TW/features/division.feature +10 -0
  72. data/examples/i18n/zh-TW/features/step_definitons/calculator_steps.rb +24 -0
  73. data/examples/i18n/zh-TW/lib/calculator.rb +14 -0
  74. data/examples/java/src/cucumber/demo/Hello.java +16 -0
  75. data/examples/jbehave/README.textile +20 -0
  76. data/examples/jbehave/features/support/env.rb +7 -0
  77. data/examples/jbehave/features/trading.feature +28 -0
  78. data/examples/jbehave/pom.xml +53 -0
  79. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/converters/TraderConverter.java +32 -0
  80. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Stock.java +42 -0
  81. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Trader.java +29 -0
  82. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/persistence/TraderPersister.java +22 -0
  83. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/scenarios/TraderSteps.java +70 -0
  84. data/examples/selenium/features/step_definitons/search_steps.rb +13 -0
  85. data/examples/selenium/features/support/env.rb +19 -0
  86. data/examples/{calculator_ruby_features → selenium_webrat}/Rakefile +0 -0
  87. data/examples/selenium_webrat/features/search.feature +9 -0
  88. data/examples/selenium_webrat/features/step_definitons/search_steps.rb +13 -0
  89. data/examples/selenium_webrat/features/support/env.rb +41 -0
  90. data/examples/self_test/README.textile +4 -1
  91. data/examples/self_test/Rakefile +6 -0
  92. data/examples/self_test/features/background/failing_background.feature +11 -0
  93. data/examples/self_test/features/background/failing_background_after_success.feature +11 -0
  94. data/examples/self_test/features/background/multiline_args_background.feature +32 -0
  95. data/examples/self_test/features/background/passing_background.feature +10 -0
  96. data/examples/self_test/features/background/pending_background.feature +10 -0
  97. data/examples/self_test/features/background/scenario_outline_failing_background.feature +16 -0
  98. data/examples/self_test/features/background/scenario_outline_passing_background.feature +16 -0
  99. data/examples/self_test/features/call_undefined_step_from_step_def.feature +7 -0
  100. data/examples/self_test/features/failing_expectation.feature +4 -0
  101. data/examples/self_test/features/lots_of_undefined.feature +8 -0
  102. data/examples/self_test/features/outline_sample.feature +11 -5
  103. data/examples/self_test/features/sample.feature +8 -3
  104. data/examples/self_test/features/step_definitions/sample_steps.rb +55 -4
  105. data/examples/self_test/features/support/env.rb +1 -0
  106. data/examples/self_test/features/support/tag_count_formatter.rb +25 -0
  107. data/examples/sinatra/Rakefile +6 -0
  108. data/examples/sinatra/app.rb +14 -0
  109. data/examples/sinatra/features/add.feature +11 -0
  110. data/examples/sinatra/features/step_definitions/add_steps.rb +15 -0
  111. data/examples/sinatra/features/support/env.rb +20 -0
  112. data/examples/sinatra/views/add.erb +5 -0
  113. data/examples/sinatra/views/layout.erb +8 -0
  114. data/examples/tickets/Rakefile +13 -8
  115. data/examples/tickets/cucumber.yml +2 -1
  116. data/examples/tickets/features/172.feature +28 -0
  117. data/examples/tickets/features/177/1.feature +29 -0
  118. data/examples/tickets/features/177/2.feature +21 -0
  119. data/examples/tickets/features/177/3.feature +18 -0
  120. data/examples/tickets/features/180.feature +7 -0
  121. data/examples/tickets/features/236.feature +13 -0
  122. data/examples/tickets/features/241.feature +13 -0
  123. data/examples/tickets/features/scenario_outline.feature +6 -1
  124. data/examples/tickets/features/step_definitons/tickets_steps.rb +41 -4
  125. data/examples/tickets/features/tickets.feature +5 -1
  126. data/features/background.feature +221 -0
  127. data/features/cucumber_cli.feature +263 -97
  128. data/features/cucumber_cli_diff_disabled.feature +45 -0
  129. data/features/cucumber_cli_outlines.feature +50 -42
  130. data/features/custom_formatter.feature +11 -0
  131. data/features/report_called_undefined_steps.feature +34 -0
  132. data/features/step_definitions/cucumber_steps.rb +6 -3
  133. data/features/step_definitions/extra_steps.rb +1 -1
  134. data/features/support/env.rb +3 -2
  135. data/gem_tasks/features.rake +1 -1
  136. data/gem_tasks/flog.rake +1 -1
  137. data/gem_tasks/gemspec.rake +2 -2
  138. data/gem_tasks/jar.rake +67 -0
  139. data/gem_tasks/rspec.rake +2 -0
  140. data/lib/autotest/cucumber_mixin.rb +18 -23
  141. data/lib/cucumber.rb +55 -11
  142. data/lib/cucumber/ast.rb +29 -0
  143. data/lib/cucumber/ast/background.rb +50 -0
  144. data/lib/cucumber/ast/comment.rb +26 -0
  145. data/lib/cucumber/ast/examples.rb +38 -0
  146. data/lib/cucumber/ast/feature.rb +62 -0
  147. data/lib/cucumber/ast/feature_element.rb +46 -0
  148. data/lib/cucumber/ast/features.rb +20 -0
  149. data/lib/cucumber/ast/outline_table.rb +81 -0
  150. data/lib/cucumber/ast/py_string.rb +58 -0
  151. data/lib/cucumber/ast/scenario.rb +64 -0
  152. data/lib/cucumber/ast/scenario_outline.rb +90 -0
  153. data/lib/cucumber/ast/step.rb +122 -0
  154. data/lib/cucumber/ast/step_collection.rb +66 -0
  155. data/lib/cucumber/ast/step_invocation.rb +110 -0
  156. data/lib/cucumber/ast/table.rb +318 -0
  157. data/lib/cucumber/ast/tags.rb +33 -0
  158. data/lib/cucumber/ast/visitor.rb +125 -0
  159. data/lib/cucumber/broadcaster.rb +2 -9
  160. data/lib/cucumber/cli/configuration.rb +364 -0
  161. data/lib/cucumber/cli/language_help_formatter.rb +59 -0
  162. data/lib/cucumber/cli/main.rb +109 -0
  163. data/lib/cucumber/core_ext/exception.rb +41 -8
  164. data/lib/cucumber/core_ext/instance_exec.rb +54 -0
  165. data/lib/cucumber/core_ext/proc.rb +29 -65
  166. data/lib/cucumber/core_ext/string.rb +19 -0
  167. data/lib/cucumber/formatter.rb +1 -0
  168. data/lib/cucumber/{formatters → formatter}/ansicolor.rb +13 -16
  169. data/lib/cucumber/formatter/color_io.rb +23 -0
  170. data/lib/cucumber/formatter/console.rb +109 -0
  171. data/lib/cucumber/formatter/cucumber.css +55 -0
  172. data/lib/cucumber/formatter/cucumber.sass +49 -0
  173. data/lib/cucumber/formatter/html.rb +133 -0
  174. data/lib/cucumber/formatter/pretty.rb +179 -0
  175. data/lib/cucumber/formatter/profile.rb +77 -0
  176. data/lib/cucumber/formatter/progress.rb +60 -0
  177. data/lib/cucumber/formatter/rerun.rb +35 -0
  178. data/lib/cucumber/formatter/unicode.rb +35 -0
  179. data/lib/cucumber/formatters/unicode.rb +2 -35
  180. data/lib/cucumber/jbehave.rb +97 -0
  181. data/lib/cucumber/languages.yml +196 -80
  182. data/lib/cucumber/parser.rb +43 -0
  183. data/lib/cucumber/parser/basic.rb +0 -0
  184. data/lib/cucumber/parser/feature.rb +1487 -0
  185. data/lib/cucumber/parser/feature.tt +193 -0
  186. data/lib/cucumber/parser/i18n.tt +31 -0
  187. data/lib/cucumber/parser/table.rb +402 -0
  188. data/lib/cucumber/parser/table.tt +59 -0
  189. data/lib/cucumber/parser/treetop_ext.rb +75 -0
  190. data/lib/cucumber/platform.rb +2 -17
  191. data/lib/cucumber/rails/rspec.rb +5 -9
  192. data/lib/cucumber/rails/world.rb +2 -2
  193. data/lib/cucumber/rake/task.rb +39 -7
  194. data/lib/cucumber/step_definition.rb +103 -0
  195. data/lib/cucumber/step_match.rb +49 -0
  196. data/lib/cucumber/step_mother.rb +183 -67
  197. data/lib/cucumber/version.rb +2 -2
  198. data/lib/cucumber/world.rb +53 -1
  199. data/rails_generators/cucumber/cucumber_generator.rb +22 -3
  200. data/rails_generators/cucumber/templates/cucumber +2 -1
  201. data/rails_generators/cucumber/templates/cucumber.rake +13 -5
  202. data/rails_generators/cucumber/templates/env.rb +4 -3
  203. data/rails_generators/cucumber/templates/paths.rb +18 -11
  204. data/rails_generators/cucumber/templates/webrat_steps.rb +41 -25
  205. data/rails_generators/feature/feature_generator.rb +4 -0
  206. data/rails_generators/feature/templates/steps.erb +0 -4
  207. data/spec/cucumber/ast/background_spec.rb +49 -0
  208. data/spec/cucumber/ast/feature_factory.rb +63 -0
  209. data/spec/cucumber/ast/feature_spec.rb +37 -0
  210. data/spec/cucumber/ast/py_string_spec.rb +47 -0
  211. data/spec/cucumber/ast/scenario_outline_spec.rb +67 -0
  212. data/spec/cucumber/ast/scenario_spec.rb +65 -0
  213. data/spec/cucumber/ast/step_collection_spec.rb +8 -0
  214. data/spec/cucumber/ast/step_spec.rb +66 -0
  215. data/spec/cucumber/ast/table_spec.rb +149 -0
  216. data/spec/cucumber/ast/tags_spec.rb +19 -0
  217. data/spec/cucumber/broadcaster_spec.rb +6 -18
  218. data/spec/cucumber/cli/configuration_spec.rb +275 -0
  219. data/spec/cucumber/cli/main_spec.rb +203 -0
  220. data/spec/cucumber/core_ext/proc_spec.rb +27 -35
  221. data/spec/cucumber/core_ext/string_spec.rb +8 -0
  222. data/spec/cucumber/{formatters → formatter}/ansicolor_spec.rb +2 -2
  223. data/spec/cucumber/formatter/color_io_spec.rb +26 -0
  224. data/spec/cucumber/formatter/html/cucumber.css +37 -0
  225. data/spec/cucumber/formatter/html/cucumber.js +13 -0
  226. data/spec/cucumber/formatter/html/index.html +45 -0
  227. data/spec/cucumber/formatter/html/jquery-1.3.min.js +19 -0
  228. data/spec/cucumber/formatter/html/jquery.uitableedit.js +100 -0
  229. data/spec/cucumber/formatters/profile_formatter_spec.rb +17 -16
  230. data/spec/cucumber/parser/feature_parser_spec.rb +282 -0
  231. data/spec/cucumber/parser/table_parser_spec.rb +48 -0
  232. data/spec/cucumber/step_definition_spec.rb +81 -0
  233. data/spec/cucumber/step_mother_spec.rb +50 -51
  234. data/spec/cucumber/treetop_parser/empty_feature.feature +1 -1
  235. data/spec/cucumber/treetop_parser/multiple_tables.feature +6 -8
  236. data/spec/cucumber/treetop_parser/scenario_outline.feature +1 -1
  237. data/spec/cucumber/treetop_parser/spaces.feature +3 -1
  238. data/spec/cucumber/treetop_parser/with_comments.feature +1 -1
  239. data/spec/cucumber/treetop_parser/with_tags.feature +18 -0
  240. data/spec/cucumber/world/pending_spec.rb +13 -12
  241. data/spec/spec_helper.rb +1 -1
  242. metadata +165 -88
  243. data/examples/calculator_ruby_features/features/addition.rb +0 -39
  244. data/examples/calculator_ruby_features/features/step_definitons/calculator_steps.rb +0 -43
  245. data/examples/i18n/ja/README.txt +0 -5
  246. data/examples/selenium/features/step_definitons/stories_steps.rb +0 -40
  247. data/gem_tasks/treetop.rake +0 -41
  248. data/lib/cucumber/cli.rb +0 -356
  249. data/lib/cucumber/executor.rb +0 -205
  250. data/lib/cucumber/formatters.rb +0 -1
  251. data/lib/cucumber/formatters/autotest_formatter.rb +0 -23
  252. data/lib/cucumber/formatters/cucumber.css +0 -132
  253. data/lib/cucumber/formatters/cucumber.js +0 -11
  254. data/lib/cucumber/formatters/html_formatter.rb +0 -151
  255. data/lib/cucumber/formatters/jquery.js +0 -32
  256. data/lib/cucumber/formatters/pretty_formatter.rb +0 -285
  257. data/lib/cucumber/formatters/profile_formatter.rb +0 -92
  258. data/lib/cucumber/formatters/progress_formatter.rb +0 -61
  259. data/lib/cucumber/model.rb +0 -1
  260. data/lib/cucumber/model/table.rb +0 -32
  261. data/lib/cucumber/step_methods.rb +0 -49
  262. data/lib/cucumber/tree.rb +0 -16
  263. data/lib/cucumber/tree/feature.rb +0 -105
  264. data/lib/cucumber/tree/features.rb +0 -21
  265. data/lib/cucumber/tree/given_scenario.rb +0 -13
  266. data/lib/cucumber/tree/scenario.rb +0 -240
  267. data/lib/cucumber/tree/step.rb +0 -173
  268. data/lib/cucumber/tree/table.rb +0 -26
  269. data/lib/cucumber/tree/top_down_visitor.rb +0 -23
  270. data/lib/cucumber/treetop_parser/feature.treetop.erb +0 -254
  271. data/lib/cucumber/treetop_parser/feature_ar.rb +0 -1951
  272. data/lib/cucumber/treetop_parser/feature_cy.rb +0 -1951
  273. data/lib/cucumber/treetop_parser/feature_da.rb +0 -1951
  274. data/lib/cucumber/treetop_parser/feature_de.rb +0 -1951
  275. data/lib/cucumber/treetop_parser/feature_en-lol.rb +0 -1951
  276. data/lib/cucumber/treetop_parser/feature_en-tx.rb +0 -1951
  277. data/lib/cucumber/treetop_parser/feature_en.rb +0 -1951
  278. data/lib/cucumber/treetop_parser/feature_es.rb +0 -1951
  279. data/lib/cucumber/treetop_parser/feature_et.rb +0 -1951
  280. data/lib/cucumber/treetop_parser/feature_fr.rb +0 -1951
  281. data/lib/cucumber/treetop_parser/feature_id.rb +0 -1951
  282. data/lib/cucumber/treetop_parser/feature_it.rb +0 -1951
  283. data/lib/cucumber/treetop_parser/feature_ja.rb +0 -1951
  284. data/lib/cucumber/treetop_parser/feature_ko.rb +0 -1951
  285. data/lib/cucumber/treetop_parser/feature_lt.rb +0 -1951
  286. data/lib/cucumber/treetop_parser/feature_nl.rb +0 -1951
  287. data/lib/cucumber/treetop_parser/feature_no.rb +0 -1951
  288. data/lib/cucumber/treetop_parser/feature_parser.rb +0 -36
  289. data/lib/cucumber/treetop_parser/feature_pl.rb +0 -1951
  290. data/lib/cucumber/treetop_parser/feature_pt.rb +0 -1951
  291. data/lib/cucumber/treetop_parser/feature_ro.rb +0 -1951
  292. data/lib/cucumber/treetop_parser/feature_ro2.rb +0 -1951
  293. data/lib/cucumber/treetop_parser/feature_ru.rb +0 -1951
  294. data/lib/cucumber/treetop_parser/feature_se.rb +0 -1951
  295. data/lib/cucumber/treetop_parser/feature_zh-CN.rb +0 -1951
  296. data/lib/cucumber/world/pending.rb +0 -22
  297. data/script/console +0 -10
  298. data/script/console.cmd +0 -1
  299. data/script/destroy +0 -14
  300. data/script/destroy.cmd +0 -1
  301. data/script/generate +0 -14
  302. data/script/generate.cmd +0 -1
  303. data/script/txt2html +0 -74
  304. data/script/txt2html.cmd +0 -1
  305. data/setup.rb +0 -1585
  306. data/spec/cucumber/cli_spec.rb +0 -521
  307. data/spec/cucumber/executor_spec.rb +0 -382
  308. data/spec/cucumber/formatters/autotest_formatter_spec.rb +0 -26
  309. data/spec/cucumber/formatters/features.html +0 -269
  310. data/spec/cucumber/formatters/html_formatter_spec.rb +0 -104
  311. data/spec/cucumber/formatters/pretty_formatter_spec.rb +0 -410
  312. data/spec/cucumber/formatters/progress_formatter_spec.rb +0 -81
  313. data/spec/cucumber/model/table_spec.rb +0 -32
  314. data/spec/cucumber/tree/feature_spec.rb +0 -122
  315. data/spec/cucumber/tree/row_scenario_outline_spec.rb +0 -73
  316. data/spec/cucumber/tree/row_scenario_spec.rb +0 -55
  317. data/spec/cucumber/tree/row_step_outline_spec.rb +0 -38
  318. data/spec/cucumber/tree/scenario_outline_spec.rb +0 -50
  319. data/spec/cucumber/tree/scenario_spec.rb +0 -134
  320. data/spec/cucumber/tree/step_outline_spec.rb +0 -17
  321. data/spec/cucumber/tree/step_spec.rb +0 -59
  322. data/spec/cucumber/treetop_parser/feature_parser_spec.rb +0 -120
@@ -0,0 +1,318 @@
1
+ module Cucumber
2
+ module Ast
3
+ # Holds the data of a table parsed from a feature file:
4
+ #
5
+ # | a | b |
6
+ # | c | d |
7
+ #
8
+ # This gets parsed into a Table holding the values <tt>[['a', 'b'], ['c', 'd']]</tt>
9
+ #
10
+ class Table
11
+ NULL_CONVERSIONS = Hash.new(lambda{ |cell_value| cell_value }).freeze
12
+
13
+ attr_accessor :file
14
+
15
+ def initialize(raw, conversions = NULL_CONVERSIONS.dup)
16
+ # Verify that it's square
17
+ raw.transpose
18
+ @raw = raw
19
+ @cells_class = Cells
20
+ @cell_class = Cell
21
+ @conversion_procs = conversions
22
+ end
23
+
24
+ # Creates a copy of this table, inheriting the column mappings.
25
+ def dup
26
+ self.class.new(@raw.dup, @conversion_procs.dup)
27
+ end
28
+
29
+ # Returns a new, transposed table. Example:
30
+ #
31
+ # | a | 7 | 4 |
32
+ # | b | 9 | 2 |
33
+ #
34
+ # Gets converted into the following:
35
+ #
36
+ # | a | b |
37
+ # | 7 | 9 |
38
+ # | 4 | 2 |
39
+ #
40
+ def transpose
41
+ self.class.new(@raw.transpose, @conversion_procs.dup)
42
+ end
43
+
44
+ # Converts this table into an Array of Hash where the keys of each
45
+ # Hash are the headers in the table. For example, a Table built from
46
+ # the following plain text:
47
+ #
48
+ # | a | b | sum |
49
+ # | 2 | 3 | 5 |
50
+ # | 7 | 9 | 16 |
51
+ #
52
+ # Gets converted into the following:
53
+ #
54
+ # [{'a' => '2', 'b' => '3', 'sum' => '5'}, {'a' => '7', 'b' => '9', 'sum' => '16'}]
55
+ #
56
+ # Use #map_column! to specify how values in a column are converted.
57
+ #
58
+ def hashes
59
+ @hashes ||= cells_rows[1..-1].map do |row|
60
+ row.to_hash
61
+ end
62
+ end
63
+
64
+ # Gets the raw data of this table. For example, a Table built from
65
+ # the following plain text:
66
+ #
67
+ # | a | b |
68
+ # | c | d |
69
+ #
70
+ # Get converted into the following:
71
+ #
72
+ # [['a', 'b], ['c', 'd']]
73
+ #
74
+ def raw
75
+ @raw
76
+ end
77
+
78
+ # Same as #raw, but skips the first (header) row
79
+ def rows
80
+ @raw[1..-1]
81
+ end
82
+
83
+ def each_cells_row(&proc)
84
+ cells_rows.each(&proc)
85
+ end
86
+
87
+ def matches_lines?(lines)
88
+ cells_rows.detect{|row| row.matches_lines?(lines)}
89
+ end
90
+
91
+ def accept(visitor)
92
+ cells_rows.each do |row|
93
+ visitor.visit_table_row(row)
94
+ end
95
+ nil
96
+ end
97
+
98
+ def status=(status)
99
+ cells_rows.each do |row|
100
+ row.status = status
101
+ end
102
+ end
103
+
104
+ # For testing only
105
+ def to_sexp #:nodoc:
106
+ [:table, *cells_rows.map{|row| row.to_sexp}]
107
+ end
108
+
109
+ # Returns a new Table where the headers are redefined. This makes it
110
+ # possible to use prettier header names in the features. Example:
111
+ #
112
+ # | Phone Number | Address |
113
+ # | 123456 | xyz |
114
+ # | 345678 | abc |
115
+ #
116
+ # A StepDefinition receiving this table can then map the columns:
117
+ #
118
+ # mapped_table = table.map_columns('Phone Number' => :phone, 'Address' => :address)
119
+ # hashes = mapped_table.hashes
120
+ # # => [{:phone => '123456', :address => 'xyz'}, {:phone => '345678', :address => 'abc'}]
121
+ #
122
+ def map_headers(mappings)
123
+ table = self.dup
124
+ table.map_headers!(mappings)
125
+ table
126
+ end
127
+
128
+ # Change how #hashes converts column values. The +column_name+ argument identifies the column
129
+ # and +conversion_proc+ performs the conversion for each cell in that column. If +strict+ is
130
+ # true, an error will be raised if the column named +column_name+ is not found. If +strict+
131
+ # is false, no error will be raised. Example:
132
+ #
133
+ # Given /^an expense report for (.*) with the following posts:$/ do |table|
134
+ # posts_table.map_column!('amount') { |a| a.to_i }
135
+ # posts_table.hashes.each do |post|
136
+ # # post['amount'] is a Fixnum, rather than a String
137
+ # end
138
+ # end
139
+ #
140
+ def map_column!(column_name, strict=true, &conversion_proc)
141
+ verify_column(column_name) if strict
142
+ @conversion_procs[column_name] = conversion_proc
143
+ end
144
+
145
+ def to_hash(cells) #:nodoc:
146
+ hash = Hash.new do |hash, key|
147
+ hash[key.to_s] if key.is_a?(Symbol)
148
+ end
149
+ @raw[0].each_with_index do |column_name, column_index|
150
+ value = @conversion_procs[column_name].call(cells.value(column_index))
151
+ hash[column_name] = value
152
+ end
153
+ hash
154
+ end
155
+
156
+ def index(cells) #:nodoc:
157
+ cells_rows.index(cells)
158
+ end
159
+
160
+ def verify_column(column_name)
161
+ raise %{The column named "#{column_name}" does not exist} unless @raw[0].include?(column_name)
162
+ end
163
+
164
+ def arguments_replaced(arguments) #:nodoc:
165
+ raw_with_replaced_args = raw.map do |row|
166
+ row.map do |cell|
167
+ cell_with_replaced_args = cell
168
+ arguments.each do |name, value|
169
+ if cell_with_replaced_args && cell_with_replaced_args.include?(name)
170
+ cell_with_replaced_args = value ? cell_with_replaced_args.gsub(name, value) : nil
171
+ end
172
+ end
173
+ cell_with_replaced_args
174
+ end
175
+ end
176
+ Table.new(raw_with_replaced_args)
177
+ end
178
+
179
+ def cells_rows
180
+ @rows ||= cell_matrix.map do |cell_row|
181
+ @cells_class.new(self, cell_row)
182
+ end
183
+ end
184
+
185
+ def header_cell(col)
186
+ cells_rows[0][col]
187
+ end
188
+
189
+ protected
190
+
191
+ def map_headers!(mappings)
192
+ headers = @raw[0]
193
+ mappings.each_pair do |pre, post|
194
+ headers[headers.index(pre)] = post
195
+ if @conversion_procs.has_key?(pre)
196
+ @conversion_procs[post] = @conversion_procs.delete(pre)
197
+ end
198
+ end
199
+ end
200
+
201
+ private
202
+
203
+ def col_width(col)
204
+ columns[col].__send__(:width)
205
+ end
206
+
207
+ def columns
208
+ @columns ||= cell_matrix.transpose.map do |cell_row|
209
+ @cells_class.new(self, cell_row)
210
+ end
211
+ end
212
+
213
+ def cell_matrix
214
+ row = -1
215
+ @cell_matrix ||= @raw.map do |raw_row|
216
+ line = raw_row.line rescue -1
217
+ row += 1
218
+ col = -1
219
+ raw_row.map do |raw_cell|
220
+ col += 1
221
+ @cell_class.new(raw_cell, self, row, col, line)
222
+ end
223
+ end
224
+ end
225
+
226
+ # Represents a row of cells or columns of cells
227
+ class Cells
228
+ include Enumerable
229
+ attr_reader :exception
230
+
231
+ def initialize(table, cells)
232
+ @table, @cells = table, cells
233
+ end
234
+
235
+ def matches_lines?(lines)
236
+ lines.index(line)
237
+ end
238
+
239
+ def accept(visitor)
240
+ each do |cell|
241
+ visitor.visit_table_cell(cell)
242
+ end
243
+ nil
244
+ end
245
+
246
+ # For testing only
247
+ def to_sexp #:nodoc:
248
+ [:row, *@cells.map{|cell| cell.to_sexp}]
249
+ end
250
+
251
+ def to_hash #:nodoc:
252
+ @to_hash ||= @table.to_hash(self)
253
+ end
254
+
255
+ def value(n) #:nodoc:
256
+ self[n].value
257
+ end
258
+
259
+ def [](n)
260
+ @cells[n]
261
+ end
262
+
263
+ def line
264
+ @cells[0].line
265
+ end
266
+
267
+ def status=(status)
268
+ each do |cell|
269
+ cell.status = status
270
+ end
271
+ end
272
+
273
+ private
274
+
275
+ def index
276
+ @table.index(self)
277
+ end
278
+
279
+ def width
280
+ map{|cell| cell.value ? cell.value.to_s.jlength : 0}.max
281
+ end
282
+
283
+ def each(&proc)
284
+ @cells.each(&proc)
285
+ end
286
+ end
287
+
288
+ class Cell
289
+ attr_reader :value, :line
290
+ attr_writer :status
291
+
292
+ def initialize(value, table, row, col, line)
293
+ @value, @table, @row, @col, @line = value, table, row, col, line
294
+ @status = :passed
295
+ end
296
+
297
+ def accept(visitor)
298
+ visitor.visit_table_cell_value(@value, col_width, @status)
299
+ end
300
+
301
+ def header_cell
302
+ @table.header_cell(@col)
303
+ end
304
+
305
+ # For testing only
306
+ def to_sexp #:nodoc:
307
+ [:cell, @value]
308
+ end
309
+
310
+ private
311
+
312
+ def col_width
313
+ @col_width ||= @table.__send__(:col_width, @col)
314
+ end
315
+ end
316
+ end
317
+ end
318
+ end
@@ -0,0 +1,33 @@
1
+ module Cucumber
2
+ module Ast
3
+ # Holds the names of tags parsed from a feature file:
4
+ #
5
+ # @invoice @release_2
6
+ #
7
+ # This gets stored internally as <tt>["invoice", "release_2"]</tt>
8
+ #
9
+ class Tags
10
+ def initialize(line, tag_names)
11
+ @line, @tag_names = line, tag_names
12
+ end
13
+
14
+ def has_tags?(tags)
15
+ (@tag_names & tags).any?
16
+ end
17
+
18
+ def matches_lines?(lines)
19
+ lines.index(@line)
20
+ end
21
+
22
+ def accept(visitor)
23
+ @tag_names.each do |tag_name|
24
+ visitor.visit_tag_name(tag_name)
25
+ end
26
+ end
27
+
28
+ def to_sexp
29
+ @tag_names.map{|tag_name| [:tag, tag_name]}
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,125 @@
1
+ module Cucumber
2
+ module Ast
3
+ # A dumb visitor that implements the whole Visitor API and just walks the tree.
4
+ class Visitor
5
+ attr_accessor :options
6
+ attr_reader :step_mother
7
+
8
+ def initialize(step_mother)
9
+ @options = {}
10
+ @step_mother = step_mother
11
+ @current_feature_lines = []
12
+ end
13
+
14
+ def current_feature_lines=(lines)
15
+ @current_feature_lines = lines
16
+ end
17
+
18
+ def matches_lines?(node)
19
+ @current_feature_lines.empty? || node.matches_lines?(@current_feature_lines)
20
+ end
21
+
22
+ def included_by_tags?(node)
23
+ tags = options[:include_tags] || []
24
+ tags.empty? || node.has_tags?(tags)
25
+ end
26
+
27
+ def excluded_by_tags?(node)
28
+ tags = options[:exclude_tags] || []
29
+ tags.any? && node.has_tags?(tags)
30
+ end
31
+
32
+ def matches_scenario_names?(node)
33
+ scenario_names = options[:scenario_names] || []
34
+ scenario_names.empty? || node.matches_scenario_names?(scenario_names)
35
+ end
36
+
37
+ def visit_features(features)
38
+ features.accept(self)
39
+ end
40
+
41
+ def visit_feature(feature)
42
+ feature.accept(self)
43
+ end
44
+
45
+ def visit_comment(comment)
46
+ comment.accept(self)
47
+ end
48
+
49
+ def visit_comment_line(comment_line)
50
+ end
51
+
52
+ def visit_tags(tags)
53
+ tags.accept(self)
54
+ end
55
+
56
+ def visit_tag_name(tag_name)
57
+ end
58
+
59
+ def visit_feature_name(name)
60
+ end
61
+
62
+ # +feature_element+ is either Scenario or ScenarioOutline
63
+ def visit_feature_element(feature_element)
64
+ feature_element.accept(self)
65
+ end
66
+
67
+ def visit_background(background)
68
+ background.accept(self)
69
+ end
70
+
71
+ def visit_background_name(keyword, name, file_colon_line, source_indent)
72
+ end
73
+
74
+ def visit_examples(examples)
75
+ examples.accept(self)
76
+ end
77
+
78
+ def visit_examples_name(keyword, name)
79
+ end
80
+
81
+ def visit_outline_table(outline_table)
82
+ outline_table.accept(self)
83
+ end
84
+
85
+ def visit_scenario_name(keyword, name, file_colon_line, source_indent)
86
+ end
87
+
88
+ def visit_steps(steps)
89
+ steps.accept(self)
90
+ end
91
+
92
+ def visit_step(step)
93
+ step.accept(self)
94
+ end
95
+
96
+ def visit_step_name(keyword, step_match, status, source_indent, background)
97
+ end
98
+
99
+ def visit_multiline_arg(multiline_arg)
100
+ multiline_arg.accept(self)
101
+ end
102
+
103
+ def visit_py_string(string, status)
104
+ end
105
+
106
+ def visit_table_row(table_row)
107
+ table_row.accept(self)
108
+ end
109
+
110
+ def visit_table_cell(table_cell)
111
+ table_cell.accept(self)
112
+ end
113
+
114
+ def visit_table_cell_value(value, width, status)
115
+ end
116
+
117
+ def visit_exception(exception, status)
118
+ end
119
+
120
+ def announce(announcement)
121
+ end
122
+
123
+ end
124
+ end
125
+ end