notch8-cucumber 0.1.99.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (312) hide show
  1. data/History.txt +525 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +318 -0
  4. data/README.txt +4 -0
  5. data/Rakefile +8 -0
  6. data/bin/cucumber +6 -0
  7. data/config/hoe.rb +76 -0
  8. data/config/requirements.rb +15 -0
  9. data/cucumber.yml +1 -0
  10. data/examples/cs/README.textile +1 -0
  11. data/examples/cs/Rakefile +12 -0
  12. data/examples/cs/compile.bat +1 -0
  13. data/examples/cs/features/addition.feature +16 -0
  14. data/examples/cs/features/step_definitons/calculator_steps.rb +19 -0
  15. data/examples/cs/src/demo/Calculator.cs +20 -0
  16. data/examples/dos_line_endings/Rakefile +6 -0
  17. data/examples/dos_line_endings/features/dos_line_endings.feature +9 -0
  18. data/examples/i18n/README.textile +18 -0
  19. data/examples/i18n/Rakefile +32 -0
  20. data/examples/i18n/ar/Rakefile +6 -0
  21. data/examples/i18n/ar/features/addition.feature +16 -0
  22. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +24 -0
  23. data/examples/i18n/ar/lib/calculator.rb +10 -0
  24. data/examples/i18n/da/Rakefile +6 -0
  25. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +24 -0
  26. data/examples/i18n/da/features/summering.feature +17 -0
  27. data/examples/i18n/da/lib/kalkulator.rb +11 -0
  28. data/examples/i18n/de/Rakefile +6 -0
  29. data/examples/i18n/de/features/addition.feature +16 -0
  30. data/examples/i18n/de/features/division.feature +9 -0
  31. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +24 -0
  32. data/examples/i18n/de/lib/calculator.rb +14 -0
  33. data/examples/i18n/en/Rakefile +6 -0
  34. data/examples/i18n/en/features/addition.feature +16 -0
  35. data/examples/i18n/en/features/division.feature +9 -0
  36. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +24 -0
  37. data/examples/i18n/en/lib/calculator.rb +14 -0
  38. data/examples/i18n/es/Rakefile +6 -0
  39. data/examples/i18n/es/features/adicion.feature +16 -0
  40. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +21 -0
  41. data/examples/i18n/es/lib/calculador.rb +14 -0
  42. data/examples/i18n/et/Rakefile +6 -0
  43. data/examples/i18n/et/features/liitmine.feature +16 -0
  44. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +24 -0
  45. data/examples/i18n/et/lib/kalkulaator.rb +14 -0
  46. data/examples/i18n/fi/Rakefile +6 -0
  47. data/examples/i18n/fi/features/jakolasku.feature +9 -0
  48. data/examples/i18n/fi/features/step_definitons/laskin_steps.rb +24 -0
  49. data/examples/i18n/fi/features/yhteenlasku.feature +16 -0
  50. data/examples/i18n/fi/lib/laskin.rb +14 -0
  51. data/examples/i18n/fr/Rakefile +6 -0
  52. data/examples/i18n/fr/features/addition.feature +17 -0
  53. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +25 -0
  54. data/examples/i18n/fr/lib/calculatrice.rb +10 -0
  55. data/examples/i18n/id/Rakefile +6 -0
  56. data/examples/i18n/id/features/addition.feature +16 -0
  57. data/examples/i18n/id/features/division.feature +9 -0
  58. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +24 -0
  59. data/examples/i18n/id/lib/calculator.rb +14 -0
  60. data/examples/i18n/it/Rakefile +6 -0
  61. data/examples/i18n/it/features/somma.feature +10 -0
  62. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +24 -0
  63. data/examples/i18n/it/lib/calcolatrice.rb +11 -0
  64. data/examples/i18n/ja/Rakefile +6 -0
  65. data/examples/i18n/ja/features/addition.feature +16 -0
  66. data/examples/i18n/ja/features/division.feature +9 -0
  67. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +24 -0
  68. data/examples/i18n/ja/lib/calculator.rb +14 -0
  69. data/examples/i18n/ko/Rakefile +6 -0
  70. data/examples/i18n/ko/features/addition.feature +16 -0
  71. data/examples/i18n/ko/features/division.feature +10 -0
  72. data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +24 -0
  73. data/examples/i18n/ko/lib/calculator.rb +14 -0
  74. data/examples/i18n/lt/Rakefile +6 -0
  75. data/examples/i18n/lt/features/addition.feature +17 -0
  76. data/examples/i18n/lt/features/division.feature +9 -0
  77. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +24 -0
  78. data/examples/i18n/lt/lib/calculator.rb +14 -0
  79. data/examples/i18n/no/Rakefile +6 -0
  80. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +17 -0
  81. data/examples/i18n/no/features/summering.feature +18 -0
  82. data/examples/i18n/no/features/support/env.rb +6 -0
  83. data/examples/i18n/no/lib/kalkulator.rb +11 -0
  84. data/examples/i18n/pt/Rakefile +6 -0
  85. data/examples/i18n/pt/features/adicao.feature +10 -0
  86. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +24 -0
  87. data/examples/i18n/pt/lib/calculadora.rb +10 -0
  88. data/examples/i18n/ro/Rakefile +6 -0
  89. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +24 -0
  90. data/examples/i18n/ro/features/suma.feature +10 -0
  91. data/examples/i18n/ro/lib/calculator.rb +11 -0
  92. data/examples/i18n/ru/Rakefile +6 -0
  93. data/examples/i18n/ru/features/addition.feature +10 -0
  94. data/examples/i18n/ru/features/consecutive_calculations.feature +16 -0
  95. data/examples/i18n/ru/features/division.feature +15 -0
  96. data/examples/i18n/ru/features/step_definitons/calculator_steps.rb +19 -0
  97. data/examples/i18n/ru/features/support/env.rb +6 -0
  98. data/examples/i18n/ru/features/support/world.rb +7 -0
  99. data/examples/i18n/ru/lib/calculator.rb +24 -0
  100. data/examples/i18n/se/Rakefile +6 -0
  101. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +24 -0
  102. data/examples/i18n/se/features/summering.feature +17 -0
  103. data/examples/i18n/se/lib/kalkulator.rb +11 -0
  104. data/examples/i18n/zh-CN/Rakefile +6 -0
  105. data/examples/i18n/zh-CN/features/addition.feature +17 -0
  106. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +26 -0
  107. data/examples/i18n/zh-CN/lib/calculator.rb +10 -0
  108. data/examples/i18n/zh-TW/Rakefile +6 -0
  109. data/examples/i18n/zh-TW/features/addition.feature +16 -0
  110. data/examples/i18n/zh-TW/features/division.feature +10 -0
  111. data/examples/i18n/zh-TW/features/step_definitons/calculator_steps.rb +24 -0
  112. data/examples/i18n/zh-TW/lib/calculator.rb +14 -0
  113. data/examples/java/README.textile +22 -0
  114. data/examples/java/Rakefile +12 -0
  115. data/examples/java/features/hello.feature +11 -0
  116. data/examples/java/features/step_definitons/hello_steps.rb +25 -0
  117. data/examples/java/features/step_definitons/tree_steps.rb +14 -0
  118. data/examples/java/features/tree.feature +9 -0
  119. data/examples/java/src/cucumber/demo/Hello.java +16 -0
  120. data/examples/jbehave/README.textile +17 -0
  121. data/examples/jbehave/features/support/env.rb +7 -0
  122. data/examples/jbehave/features/trading.feature +24 -0
  123. data/examples/jbehave/pom.xml +48 -0
  124. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/converters/TraderConverter.java +32 -0
  125. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Stock.java +42 -0
  126. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Trader.java +29 -0
  127. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/persistence/TraderPersister.java +22 -0
  128. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/scenarios/TraderSteps.java +65 -0
  129. data/examples/selenium/Rakefile +6 -0
  130. data/examples/selenium/features/search.feature +9 -0
  131. data/examples/self_test/README.textile +6 -0
  132. data/examples/self_test/Rakefile +6 -0
  133. data/examples/self_test/features/background/failing_background.feature +10 -0
  134. data/examples/self_test/features/background/failing_background_after_success.feature +11 -0
  135. data/examples/self_test/features/background/multiline_args_background.feature +32 -0
  136. data/examples/self_test/features/background/passing_background.feature +10 -0
  137. data/examples/self_test/features/background/pending_background.feature +10 -0
  138. data/examples/self_test/features/background/scenario_outline_failing_background.feature +16 -0
  139. data/examples/self_test/features/background/scenario_outline_passing_background.feature +16 -0
  140. data/examples/self_test/features/call_undefined_step_from_step_def.feature +7 -0
  141. data/examples/self_test/features/failing_expectation.feature +4 -0
  142. data/examples/self_test/features/lots_of_undefined.feature +8 -0
  143. data/examples/self_test/features/outline_sample.feature +15 -0
  144. data/examples/self_test/features/sample.feature +19 -0
  145. data/examples/self_test/features/step_definitions/sample_steps.rb +64 -0
  146. data/examples/self_test/features/support/env.rb +1 -0
  147. data/examples/self_test/features/support/tag_count_formatter.rb +25 -0
  148. data/examples/sinatra/Rakefile +6 -0
  149. data/examples/sinatra/app.rb +14 -0
  150. data/examples/sinatra/features/add.feature +11 -0
  151. data/examples/sinatra/features/step_definitions/add_steps.rb +15 -0
  152. data/examples/sinatra/features/support/env.rb +20 -0
  153. data/examples/sinatra/views/add.erb +5 -0
  154. data/examples/sinatra/views/layout.erb +8 -0
  155. data/examples/test_unit/Rakefile +6 -0
  156. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +26 -0
  157. data/examples/test_unit/features/test_unit.feature +9 -0
  158. data/examples/tickets/Rakefile +11 -0
  159. data/examples/tickets/cucumber.yml +2 -0
  160. data/examples/tickets/features/172.feature +28 -0
  161. data/examples/tickets/features/177/1.feature +29 -0
  162. data/examples/tickets/features/177/2.feature +21 -0
  163. data/examples/tickets/features/177/3.feature +18 -0
  164. data/examples/tickets/features/180.feature +7 -0
  165. data/examples/tickets/features/lib/eatting_machine.rb +18 -0
  166. data/examples/tickets/features/lib/pantry.rb +20 -0
  167. data/examples/tickets/features/scenario_outline.feature +95 -0
  168. data/examples/tickets/features/step_definitons/scenario_outline_steps.rb +42 -0
  169. data/examples/tickets/features/step_definitons/tickets_steps.rb +60 -0
  170. data/examples/tickets/features/tickets.feature +28 -0
  171. data/examples/watir/README.textile +16 -0
  172. data/examples/watir/Rakefile +6 -0
  173. data/examples/watir/features/search.feature +9 -0
  174. data/examples/watir/features/step_definitons/search_steps.rb +24 -0
  175. data/examples/watir/features/support/env.rb +32 -0
  176. data/features/background.feature +223 -0
  177. data/features/cucumber_cli.feature +366 -0
  178. data/features/cucumber_cli_diff_disabled.feature +45 -0
  179. data/features/cucumber_cli_outlines.feature +90 -0
  180. data/features/custom_formatter.feature +11 -0
  181. data/features/report_called_undefined_steps.feature +32 -0
  182. data/features/step_definitions/cucumber_steps.rb +30 -0
  183. data/features/step_definitions/extra_steps.rb +2 -0
  184. data/features/support/env.rb +8 -0
  185. data/gem_tasks/deployment.rake +11 -0
  186. data/gem_tasks/environment.rake +7 -0
  187. data/gem_tasks/features.rake +6 -0
  188. data/gem_tasks/fix_cr_lf.rake +10 -0
  189. data/gem_tasks/flog.rake +4 -0
  190. data/gem_tasks/gemspec.rake +10 -0
  191. data/gem_tasks/jar.rake +67 -0
  192. data/gem_tasks/rspec.rake +35 -0
  193. data/gem_tasks/yard.rake +8 -0
  194. data/lib/autotest/cucumber.rb +6 -0
  195. data/lib/autotest/cucumber_mixin.rb +125 -0
  196. data/lib/autotest/cucumber_rails.rb +6 -0
  197. data/lib/autotest/cucumber_rails_rspec.rb +6 -0
  198. data/lib/autotest/cucumber_rspec.rb +6 -0
  199. data/lib/autotest/discover.rb +9 -0
  200. data/lib/cucumber.rb +71 -0
  201. data/lib/cucumber/ast.rb +29 -0
  202. data/lib/cucumber/ast/background.rb +88 -0
  203. data/lib/cucumber/ast/comment.rb +26 -0
  204. data/lib/cucumber/ast/examples.rb +26 -0
  205. data/lib/cucumber/ast/feature.rb +66 -0
  206. data/lib/cucumber/ast/features.rb +39 -0
  207. data/lib/cucumber/ast/filter.rb +22 -0
  208. data/lib/cucumber/ast/outline_table.rb +49 -0
  209. data/lib/cucumber/ast/py_string.rb +52 -0
  210. data/lib/cucumber/ast/scenario.rb +103 -0
  211. data/lib/cucumber/ast/scenario_outline.rb +92 -0
  212. data/lib/cucumber/ast/step.rb +161 -0
  213. data/lib/cucumber/ast/steps.rb +13 -0
  214. data/lib/cucumber/ast/table.rb +290 -0
  215. data/lib/cucumber/ast/tags.rb +40 -0
  216. data/lib/cucumber/ast/visitor.rb +109 -0
  217. data/lib/cucumber/broadcaster.rb +27 -0
  218. data/lib/cucumber/cli/configuration.rb +356 -0
  219. data/lib/cucumber/cli/language_help_formatter.rb +59 -0
  220. data/lib/cucumber/cli/main.rb +107 -0
  221. data/lib/cucumber/core_ext/exception.rb +53 -0
  222. data/lib/cucumber/core_ext/instance_exec.rb +54 -0
  223. data/lib/cucumber/core_ext/proc.rb +33 -0
  224. data/lib/cucumber/core_ext/string.rb +48 -0
  225. data/lib/cucumber/formatter.rb +1 -0
  226. data/lib/cucumber/formatter/ansicolor.rb +103 -0
  227. data/lib/cucumber/formatter/color_io.rb +23 -0
  228. data/lib/cucumber/formatter/console.rb +119 -0
  229. data/lib/cucumber/formatter/cucumber.css +55 -0
  230. data/lib/cucumber/formatter/cucumber.sass +49 -0
  231. data/lib/cucumber/formatter/html.rb +130 -0
  232. data/lib/cucumber/formatter/pretty.rb +172 -0
  233. data/lib/cucumber/formatter/profile.rb +77 -0
  234. data/lib/cucumber/formatter/progress.rb +74 -0
  235. data/lib/cucumber/formatter/rerun.rb +39 -0
  236. data/lib/cucumber/formatter/unicode.rb +35 -0
  237. data/lib/cucumber/formatters/unicode.rb +2 -0
  238. data/lib/cucumber/jbehave.rb +102 -0
  239. data/lib/cucumber/languages.yml +374 -0
  240. data/lib/cucumber/parser.rb +43 -0
  241. data/lib/cucumber/parser/basic.rb +0 -0
  242. data/lib/cucumber/parser/feature.rb +1490 -0
  243. data/lib/cucumber/parser/feature.tt +188 -0
  244. data/lib/cucumber/parser/i18n.tt +31 -0
  245. data/lib/cucumber/parser/table.rb +402 -0
  246. data/lib/cucumber/parser/table.tt +59 -0
  247. data/lib/cucumber/parser/treetop_ext.rb +75 -0
  248. data/lib/cucumber/platform.rb +18 -0
  249. data/lib/cucumber/rails/rspec.rb +8 -0
  250. data/lib/cucumber/rails/world.rb +73 -0
  251. data/lib/cucumber/rake/task.rb +139 -0
  252. data/lib/cucumber/step_definition.rb +94 -0
  253. data/lib/cucumber/step_mother.rb +194 -0
  254. data/lib/cucumber/version.rb +10 -0
  255. data/rails_generators/cucumber/USAGE +11 -0
  256. data/rails_generators/cucumber/cucumber_generator.rb +50 -0
  257. data/rails_generators/cucumber/templates/cucumber +8 -0
  258. data/rails_generators/cucumber/templates/cucumber.rake +15 -0
  259. data/rails_generators/cucumber/templates/env.rb +17 -0
  260. data/rails_generators/cucumber/templates/paths.rb +19 -0
  261. data/rails_generators/cucumber/templates/webrat_steps.rb +115 -0
  262. data/rails_generators/feature/USAGE +12 -0
  263. data/rails_generators/feature/feature_generator.rb +36 -0
  264. data/rails_generators/feature/templates/feature.erb +31 -0
  265. data/rails_generators/feature/templates/steps.erb +24 -0
  266. data/spec/cucumber/ast/background_spec.rb +58 -0
  267. data/spec/cucumber/ast/feature_factory.rb +54 -0
  268. data/spec/cucumber/ast/feature_spec.rb +60 -0
  269. data/spec/cucumber/ast/py_string_spec.rb +40 -0
  270. data/spec/cucumber/ast/scenario_outline_spec.rb +64 -0
  271. data/spec/cucumber/ast/scenario_spec.rb +82 -0
  272. data/spec/cucumber/ast/step_spec.rb +45 -0
  273. data/spec/cucumber/ast/table_spec.rb +139 -0
  274. data/spec/cucumber/ast/tags_spec.rb +35 -0
  275. data/spec/cucumber/broadcaster_spec.rb +25 -0
  276. data/spec/cucumber/cli/configuration_spec.rb +268 -0
  277. data/spec/cucumber/cli/main_spec.rb +203 -0
  278. data/spec/cucumber/core_ext/proc_spec.rb +37 -0
  279. data/spec/cucumber/core_ext/string_spec.rb +42 -0
  280. data/spec/cucumber/formatter/ansicolor_spec.rb +35 -0
  281. data/spec/cucumber/formatter/color_io_spec.rb +26 -0
  282. data/spec/cucumber/formatter/html/cucumber.css +37 -0
  283. data/spec/cucumber/formatter/html/cucumber.js +13 -0
  284. data/spec/cucumber/formatter/html/index.html +45 -0
  285. data/spec/cucumber/formatter/html/jquery-1.3.min.js +19 -0
  286. data/spec/cucumber/formatter/html/jquery.uitableedit.js +100 -0
  287. data/spec/cucumber/formatters/profile_formatter_spec.rb +198 -0
  288. data/spec/cucumber/parser/feature_parser_spec.rb +281 -0
  289. data/spec/cucumber/parser/table_parser_spec.rb +48 -0
  290. data/spec/cucumber/rails/stubs/mini_rails.rb +18 -0
  291. data/spec/cucumber/rails/stubs/test_help.rb +1 -0
  292. data/spec/cucumber/rails/world_spec.rb +11 -0
  293. data/spec/cucumber/sell_cucumbers.feature +19 -0
  294. data/spec/cucumber/step_definition_spec.rb +70 -0
  295. data/spec/cucumber/step_mother_spec.rb +73 -0
  296. data/spec/cucumber/treetop_parser/empty_feature.feature +4 -0
  297. data/spec/cucumber/treetop_parser/empty_scenario.feature +9 -0
  298. data/spec/cucumber/treetop_parser/empty_scenario_outline.feature +3 -0
  299. data/spec/cucumber/treetop_parser/fit_scenario.feature +8 -0
  300. data/spec/cucumber/treetop_parser/given_scenario.feature +9 -0
  301. data/spec/cucumber/treetop_parser/invalid_scenario_outlines.feature +7 -0
  302. data/spec/cucumber/treetop_parser/multiline_steps.feature +17 -0
  303. data/spec/cucumber/treetop_parser/multiple_tables.feature +27 -0
  304. data/spec/cucumber/treetop_parser/scenario_outline.feature +16 -0
  305. data/spec/cucumber/treetop_parser/spaces.feature +12 -0
  306. data/spec/cucumber/treetop_parser/test_dos.feature +25 -0
  307. data/spec/cucumber/treetop_parser/with_comments.feature +10 -0
  308. data/spec/cucumber/treetop_parser/with_tags.feature +18 -0
  309. data/spec/cucumber/world/pending_spec.rb +47 -0
  310. data/spec/spec.opts +2 -0
  311. data/spec/spec_helper.rb +21 -0
  312. metadata +428 -0
@@ -0,0 +1,52 @@
1
+ module Cucumber
2
+ module Ast
3
+ # Represents an inline argument in a step. Example:
4
+ #
5
+ # Given the message
6
+ # """
7
+ # I like
8
+ # Cucumber sandwich
9
+ # """
10
+ #
11
+ # The text between the pair of <tt>"""</tt> is stored inside a PyString,
12
+ # which is yielded to the StepDefinition block as the last argument.
13
+ #
14
+ # The StepDefinition can then access the String via the #to_s method. In the
15
+ # example above, that would return: <tt>"I like\nCucumber sandwich"</tt>
16
+ #
17
+ # Note how the indentation from the source is stripped away.
18
+ #
19
+ class PyString
20
+ def initialize(start_line, end_line, string, quotes_indent)
21
+ @start_line, @end_line = start_line, end_line
22
+ @string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent
23
+ end
24
+
25
+ def to_s
26
+ @string.indent(-@quotes_indent)
27
+ end
28
+
29
+ def at_lines?(lines)
30
+ lines.detect{|l| l >= @start_line && l <= @end_line}
31
+ end
32
+
33
+ def accept(visitor, status)
34
+ visitor.visit_py_string(to_s, status)
35
+ end
36
+
37
+ def arguments_replaced(arguments) #:nodoc:
38
+ string = @string
39
+ arguments.each do |name, value|
40
+ string = string.gsub(name, value)
41
+ end
42
+ PyString.new(@start_line, @end_line, string, @quotes_indent)
43
+ end
44
+
45
+ # For testing only
46
+ def to_sexp #:nodoc:
47
+ [:py_string, to_s]
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,103 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Scenario
4
+ attr_writer :feature, :background
5
+
6
+ def initialize(comment, tags, line, keyword, name, steps)
7
+ @comment, @tags, @line, @keyword, @name = comment, tags, line, keyword, name
8
+ steps.each {|step| step.scenario = self}
9
+ @steps = steps
10
+ @steps_helper = Steps.new(self)
11
+ end
12
+
13
+ def status
14
+ @steps.map{|step| step.status}
15
+ end
16
+
17
+ def tagged_with?(tag_names)
18
+ @tags.among?(tag_names) || @feature.tagged_with?(tag_names, false)
19
+ end
20
+
21
+ def matches_scenario_names?(scenario_names)
22
+ scenario_names.detect{|name| @name == name}
23
+ end
24
+
25
+ def accept(visitor)
26
+ visitor.visit_background(@background) if @background
27
+ visitor.visit_comment(@comment)
28
+ visitor.visit_tags(@tags)
29
+ visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
30
+ visitor.visit_steps(@steps_helper)
31
+
32
+ @feature.scenario_executed(self) if @feature && !@executed
33
+ @executed = true
34
+ end
35
+
36
+ def accept_steps(visitor)
37
+ prior_world = @background ? @background.world : nil
38
+ visitor.world(self, prior_world) do |world|
39
+ previous = @background ? @background.status : :passed
40
+ @steps.each do |step|
41
+ step.previous = previous
42
+ step.world = world
43
+ visitor.visit_step(step)
44
+ previous = step.status
45
+ end
46
+ end
47
+ end
48
+
49
+ def source_indent(text_length)
50
+ max_line_length - text_length
51
+ end
52
+
53
+ def max_line_length
54
+ lengths = (@steps + [self]).map{|e| e.text_length}
55
+ lengths.max
56
+ end
57
+
58
+ def text_length
59
+ @keyword.jlength + @name.jlength
60
+ end
61
+
62
+ def at_lines?(lines)
63
+ at_header_or_step_lines?(lines)
64
+ end
65
+
66
+ def at_header_or_step_lines?(lines)
67
+ lines.empty? || lines.index(@line) || @steps.detect {|step| step.at_lines?(lines)} || @tags.at_lines?(lines)
68
+ end
69
+
70
+ def undefined?
71
+ @steps.empty?
72
+ end
73
+
74
+ def step_executed(step)
75
+ @feature.step_executed(step) if @feature
76
+ end
77
+
78
+ def backtrace_line(name = "#{@keyword} #{@name}", line = @line)
79
+ @feature.backtrace_line(name, line) if @feature
80
+ end
81
+
82
+ def file_line(line = @line)
83
+ @feature.file_line(line) if @feature
84
+ end
85
+
86
+ def previous_step(step)
87
+ i = @steps.index(step) || -1
88
+ @steps[i-1]
89
+ end
90
+
91
+ def to_sexp
92
+ sexp = [:scenario, @line, @keyword, @name]
93
+ comment = @comment.to_sexp
94
+ sexp += [comment] if comment
95
+ tags = @tags.to_sexp
96
+ sexp += tags if tags.any?
97
+ steps = @steps.map{|step| step.to_sexp}
98
+ sexp += steps if steps.any?
99
+ sexp
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,92 @@
1
+ module Cucumber
2
+ module Ast
3
+ class ScenarioOutline < Scenario
4
+ # The +example_sections+ argument must be an Array where each element is another array representing
5
+ # an Examples section. This array has 3 elements:
6
+ #
7
+ # * Examples keyword
8
+ # * Examples section name
9
+ # * Raw matrix
10
+ def initialize(comment, tags, line, keyword, name, steps, example_sections)
11
+ super(comment, tags, line, keyword, name, steps)
12
+ steps.each {|step| step.status = :outline}
13
+
14
+ @examples_array = example_sections.map do |example_section|
15
+ examples_line = example_section[0]
16
+ examples_keyword = example_section[1]
17
+ examples_name = example_section[2]
18
+ examples_matrix = example_section[3]
19
+
20
+ examples_table = OutlineTable.new(examples_matrix, self)
21
+ Examples.new(examples_line, examples_keyword, examples_name, examples_table)
22
+ end
23
+ end
24
+
25
+ def at_lines?(lines)
26
+ super || @examples_array.detect { |examples| examples.at_lines?(lines) }
27
+ end
28
+
29
+ def accept(visitor)
30
+ visitor.visit_background(@background) if @background
31
+ visitor.visit_comment(@comment)
32
+ visitor.visit_tags(@tags)
33
+ visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
34
+ visitor.visit_steps(@steps_helper)
35
+
36
+ @examples_array.each do |examples|
37
+ visitor.visit_examples(examples)
38
+ end
39
+ end
40
+
41
+ def each_example_row(&proc)
42
+ @examples_array.each do |examples|
43
+ examples.each_example_row(&proc)
44
+ end
45
+ end
46
+
47
+ def execute_row(cells, visitor, &proc)
48
+ exception = nil
49
+
50
+ prior_world = @background ? @background.world : nil
51
+ visitor.world(self, prior_world) do |world|
52
+
53
+ previous_status = @background ? @background.status : :passed
54
+ argument_hash = cells.to_hash
55
+ cell_index = 0
56
+ @steps.each do |step|
57
+ executed_step, previous_status, matched_args =
58
+ step.execute_with_arguments(argument_hash, world, previous_status, visitor, cells[0].line)
59
+ # There might be steps that don't have any arguments
60
+ # If there are no matched args, we'll still iterate once
61
+ matched_args = [nil] if matched_args.empty?
62
+
63
+ matched_args.each do
64
+ cell = cells[cell_index]
65
+ if cell
66
+ proc.call(cell, previous_status)
67
+ cell_index += 1
68
+ end
69
+ end
70
+ exception ||= executed_step.exception
71
+ end
72
+ end
73
+ @feature.scenario_executed(self) if @feature
74
+ exception
75
+ end
76
+
77
+ def pending? ; false ; end
78
+
79
+ def to_sexp
80
+ sexp = [:scenario_outline, @keyword, @name]
81
+ comment = @comment.to_sexp
82
+ sexp += [comment] if comment
83
+ tags = @tags.to_sexp
84
+ sexp += tags if tags.any?
85
+ steps = @steps.map{|step| step.to_sexp}
86
+ sexp += steps if steps.any?
87
+ sexp += @examples_array.map{|e| e.to_sexp}
88
+ sexp
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,161 @@
1
+ require 'cucumber/step_definition'
2
+ require 'cucumber/core_ext/string'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ class Step
7
+ attr_reader :keyword, :name
8
+ attr_writer :world, :previous, :options
9
+ attr_accessor :status, :scenario, :exception
10
+
11
+ def initialize(line, keyword, name, *multiline_args)
12
+ @line, @keyword, @name, @multiline_args = line, keyword, name, multiline_args
13
+ end
14
+
15
+ def execute_with_arguments(argument_hash, world, previous, visitor, row_line)
16
+ delimited_arguments = delimit_argument_names(argument_hash)
17
+ name = replace_name_arguments(delimited_arguments)
18
+ multiline_args = replace_multiline_args_arguments(delimited_arguments)
19
+
20
+ execute_twin(world, previous, visitor, row_line, name, *multiline_args)
21
+ end
22
+
23
+ def execute_as_new(world, previous, visitor, row_line)
24
+ execute_twin(world, previous, visitor, row_line, @name, *@multiline_args)
25
+ end
26
+
27
+ def accept(visitor)
28
+ execute(visitor)
29
+
30
+ if @status == :outline
31
+ step_definition = find_first_name_and_step_definition_from_examples(visitor)
32
+ else
33
+ step_definition = @step_definition
34
+ end
35
+ visitor.visit_step_name(@keyword, @name, @status, step_definition, source_indent)
36
+ @multiline_args.each do |multiline_arg|
37
+ visitor.visit_multiline_arg(multiline_arg, @status)
38
+ end
39
+ @exception
40
+ end
41
+
42
+ def find_first_name_and_step_definition_from_examples(visitor)
43
+ # @scenario is always a ScenarioOutline in this case
44
+ @scenario.each_example_row do |cells|
45
+ argument_hash = cells.to_hash
46
+ delimited_arguments = delimit_argument_names(argument_hash)
47
+ name = replace_name_arguments(delimited_arguments)
48
+ step_definition = visitor.step_definition(name) rescue nil
49
+ return step_definition if step_definition
50
+ end
51
+ nil
52
+ end
53
+
54
+ def to_sexp
55
+ [:step, @line, @keyword, @name, *@multiline_args.map{|arg| arg.to_sexp}]
56
+ end
57
+
58
+ def at_lines?(lines)
59
+ lines.empty? || lines.index(@line) || @multiline_args.detect{|a| a.at_lines?(lines)}
60
+ end
61
+
62
+ def source_indent
63
+ @scenario.source_indent(text_length)
64
+ end
65
+
66
+ def text_length
67
+ @keyword.jlength + @name.jlength + 2 # Add 2 because steps get indented 2 more than scenarios
68
+ end
69
+
70
+ def backtrace_line
71
+ @backtrace_line ||= @scenario.backtrace_line("#{@keyword} #{@name}", @line) unless @scenario.nil?
72
+ end
73
+
74
+ def file_line
75
+ @file_line ||= @scenario.file_line(@line) unless @scenario.nil?
76
+ end
77
+
78
+ def actual_keyword
79
+ if [Cucumber.keyword_hash['and'], Cucumber.keyword_hash['but']].index(@keyword) && previous_step
80
+ previous_step.actual_keyword
81
+ else
82
+ @keyword
83
+ end
84
+ end
85
+
86
+ protected
87
+
88
+ def previous_step
89
+ @scenario.previous_step(self)
90
+ end
91
+
92
+ private
93
+
94
+ def execute(visitor)
95
+ matched_args = []
96
+ if @status.nil?
97
+ begin
98
+ @step_definition = visitor.step_definition(@name)
99
+ matched_args = @step_definition.matched_args(@name)
100
+ if @previous == :passed && !visitor.options[:dry_run]
101
+ @world.__cucumber_current_step = self
102
+ @step_definition.execute(@name, @world, *(matched_args + @multiline_args))
103
+ @status = :passed
104
+ else
105
+ @status = :skipped
106
+ end
107
+ rescue Undefined => exception
108
+ if visitor.options[:strict]
109
+ exception.set_backtrace([])
110
+ failed(exception)
111
+ else
112
+ @status = :undefined
113
+ end
114
+ rescue Pending => exception
115
+ visitor.options[:strict] ? failed(exception) : @status = :pending
116
+ rescue Exception => exception
117
+ failed(exception)
118
+ end
119
+ @scenario.step_executed(self) if @scenario
120
+ end
121
+ [self, @status, matched_args]
122
+ end
123
+
124
+ def execute_twin(world, previous, visitor, line, name, *multiline_args)
125
+ # We'll create a new step and execute that
126
+ step = Step.new(line, @keyword, name, *multiline_args)
127
+ step.scenario = @scenario
128
+ step.world = world
129
+ step.previous = previous
130
+ step.__send__(:execute, visitor)
131
+ end
132
+
133
+ ARGUMENT_START = '<'
134
+ ARGUMENT_END = '>'
135
+
136
+ def delimit_argument_names(argument_hash)
137
+ argument_hash.inject({}) { |h,(k,v)| h["#{ARGUMENT_START}#{k}#{ARGUMENT_END}"] = v; h }
138
+ end
139
+
140
+ def replace_name_arguments(argument_hash)
141
+ name_with_arguments_replaced = @name
142
+ argument_hash.each do |name, value|
143
+ name_with_arguments_replaced = name_with_arguments_replaced.gsub(name, value) if value
144
+ end
145
+ name_with_arguments_replaced
146
+ end
147
+
148
+ def replace_multiline_args_arguments(arguments)
149
+ @multiline_args.map do |arg|
150
+ arg.arguments_replaced(arguments)
151
+ end
152
+ end
153
+
154
+ def failed(exception)
155
+ @status = :failed
156
+ @exception = exception
157
+ @exception.backtrace << backtrace_line unless backtrace_line.nil?
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,13 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Steps
4
+ def initialize(scenario)
5
+ @scenario = scenario
6
+ end
7
+
8
+ def accept(visitor)
9
+ @scenario.accept_steps(visitor)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,290 @@
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 at_lines?(lines)
88
+ cells_rows.detect { |row| row.at_lines?(lines) }
89
+ end
90
+
91
+ def accept(visitor, status)
92
+ cells_rows.each do |row|
93
+ visitor.visit_table_row(row, status)
94
+ end
95
+ nil
96
+ end
97
+
98
+ # For testing only
99
+ def to_sexp #:nodoc:
100
+ [:table, *cells_rows.map{|row| row.to_sexp}]
101
+ end
102
+
103
+ # Returns a new Table where the headers are redefined. This makes it
104
+ # possible to use prettier header names in the features. Example:
105
+ #
106
+ # | Phone Number | Address |
107
+ # | 123456 | xyz |
108
+ # | 345678 | abc |
109
+ #
110
+ # A StepDefinition receiving this table can then map the columns:
111
+ #
112
+ # mapped_table = table.map_columns('Phone Number' => :phone, 'Address' => :address)
113
+ # hashes = mapped_table.hashes
114
+ # # => [{:phone => '123456', :address => 'xyz'}, {:phone => '345678', :address => 'abc'}]
115
+ #
116
+ def map_headers(mappings)
117
+ table = self.dup
118
+ table.map_headers!(mappings)
119
+ table
120
+ end
121
+
122
+ # Change how #hashes converts column values. The +column_name+ argument identifies the column
123
+ # and +conversion_proc+ performs the conversion for each cell in that column. If +strict+ is
124
+ # true, an error will be raised if the column named +column_name+ is not found. If +strict+
125
+ # is false, no error will be raised.
126
+ def map_column!(column_name, strict=true, &conversion_proc)
127
+ verify_column(column_name) if strict
128
+ @conversion_procs[column_name] = conversion_proc
129
+ end
130
+
131
+ def to_hash(cells) #:nodoc:
132
+ hash = Hash.new do |hash, key|
133
+ hash[key.to_s] if key.is_a?(Symbol)
134
+ end
135
+ @raw[0].each_with_index do |column_name, column_index|
136
+ value = @conversion_procs[column_name].call(cells.value(column_index))
137
+ hash[column_name] = value
138
+ end
139
+ hash
140
+ end
141
+
142
+ def index(cells) #:nodoc:
143
+ cells_rows.index(cells)
144
+ end
145
+
146
+ def verify_column(column_name)
147
+ raise %{The column named "#{column_name}" does not exist} unless @raw[0].include?(column_name)
148
+ end
149
+
150
+ def arguments_replaced(arguments) #:nodoc:
151
+ raw_with_replaced_args = raw.map do |row|
152
+ row.map do |cell|
153
+ cell_with_replaced_args = cell
154
+ arguments.each do |name, value|
155
+ cell_with_replaced_args = value && !cell.nil? ? cell_with_replaced_args.gsub(name, value) : nil
156
+ end
157
+ cell_with_replaced_args
158
+ end
159
+ end
160
+
161
+ Table.new(raw_with_replaced_args)
162
+ end
163
+
164
+ def at_lines?(lines)
165
+ cells_rows.detect{|row| row.at_lines?(lines)}
166
+ end
167
+
168
+ protected
169
+
170
+ def map_headers!(mappings)
171
+ headers = @raw[0]
172
+ mappings.each_pair do |pre, post|
173
+ headers[headers.index(pre)] = post
174
+ if @conversion_procs.has_key?(pre)
175
+ @conversion_procs[post] = @conversion_procs.delete(pre)
176
+ end
177
+ end
178
+ end
179
+
180
+ private
181
+
182
+ def col_width(col)
183
+ columns[col].__send__(:width)
184
+ end
185
+
186
+ def cells_rows
187
+ @rows ||= cell_matrix.map do |cell_row|
188
+ @cells_class.new(self, cell_row)
189
+ end
190
+ end
191
+
192
+ def columns
193
+ @columns ||= cell_matrix.transpose.map do |cell_row|
194
+ @cells_class.new(self, cell_row)
195
+ end
196
+ end
197
+
198
+ def cell_matrix
199
+ row = -1
200
+ @cell_matrix ||= @raw.map do |raw_row|
201
+ line = raw_row.line rescue -1
202
+ row += 1
203
+ col = -1
204
+ raw_row.map do |raw_cell|
205
+ col += 1
206
+ @cell_class.new(raw_cell, self, row, col, line)
207
+ end
208
+ end
209
+ end
210
+
211
+ # Represents a row of cells or columns of cells
212
+ class Cells
213
+ include Enumerable
214
+
215
+ def initialize(table, cells)
216
+ @table, @cells = table, cells
217
+ end
218
+
219
+ def accept(visitor, status)
220
+ each do |cell|
221
+ visitor.visit_table_cell(cell, status)
222
+ end
223
+ nil
224
+ end
225
+
226
+ # For testing only
227
+ def to_sexp #:nodoc:
228
+ [:row, *@cells.map{|cell| cell.to_sexp}]
229
+ end
230
+
231
+ def to_hash #:nodoc:
232
+ @to_hash ||= @table.to_hash(self)
233
+ end
234
+
235
+ def value(n) #:nodoc:
236
+ self[n].value
237
+ end
238
+
239
+ def [](n)
240
+ @cells[n]
241
+ end
242
+
243
+ def line
244
+ @cells[0].line
245
+ end
246
+
247
+ def at_lines?(lines)
248
+ lines.empty? || lines.index(line)
249
+ end
250
+
251
+ private
252
+
253
+ def index
254
+ @table.index(self)
255
+ end
256
+
257
+ def width
258
+ map{|cell| cell.value ? cell.value.to_s.jlength : 0}.max
259
+ end
260
+
261
+ def each(&proc)
262
+ @cells.each(&proc)
263
+ end
264
+ end
265
+
266
+ class Cell
267
+ attr_reader :value, :line
268
+
269
+ def initialize(value, table, row, col, line)
270
+ @value, @table, @row, @col, @line = value, table, row, col, line
271
+ end
272
+
273
+ def accept(visitor, status)
274
+ visitor.visit_table_cell_value(@value, col_width, status)
275
+ end
276
+
277
+ # For testing only
278
+ def to_sexp #:nodoc:
279
+ [:cell, @value]
280
+ end
281
+
282
+ private
283
+
284
+ def col_width
285
+ @col_width ||= @table.__send__(:col_width, @col)
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end