kosmas58-cucumber 0.1.99.22 → 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 +322 -0
  4. data/README.txt +25 -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 +9 -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 +38 -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 +15 -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 +126 -0
  232. data/lib/cucumber/formatter/pretty.rb +167 -0
  233. data/lib/cucumber/formatter/profile.rb +77 -0
  234. data/lib/cucumber/formatter/progress.rb +68 -0
  235. data/lib/cucumber/formatter/rerun.rb +35 -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 +146 -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 +14 -0
  256. data/rails_generators/cucumber/cucumber_generator.rb +75 -0
  257. data/rails_generators/cucumber/templates/cucumber +8 -0
  258. data/rails_generators/cucumber/templates/cucumber.rake +20 -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 +15 -0
  263. data/rails_generators/feature/feature_generator.rb +60 -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 +14 -0
  276. data/spec/cucumber/cli/configuration_spec.rb +268 -0
  277. data/spec/cucumber/cli/main_spec.rb +204 -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 +329 -9
@@ -0,0 +1,194 @@
1
+ require 'cucumber/step_definition'
2
+ require 'cucumber/core_ext/instance_exec'
3
+
4
+ module Cucumber
5
+ class Undefined < StandardError
6
+ attr_reader :step_name
7
+
8
+ def initialize(step_name)
9
+ super %{Undefined step: "#{step_name}"}
10
+ @step_name = step_name
11
+ end
12
+ Cucumber::EXCEPTION_STATUS[self] = :undefined
13
+ end
14
+
15
+ class Pending < StandardError
16
+ Cucumber::EXCEPTION_STATUS[self] = :pending
17
+ end
18
+
19
+ # Raised when a step matches 2 or more StepDefinition
20
+ class Ambiguous < StandardError
21
+ def initialize(step_name, step_definitions)
22
+ message = "Ambiguous match of \"#{step_name}\":\n\n"
23
+ message << step_definitions.map{|sd| sd.to_backtrace_line}.join("\n")
24
+ message << "\n\n"
25
+ super(message)
26
+ end
27
+ end
28
+
29
+ # Raised when 2 or more StepDefinition have the same Regexp
30
+ class Redundant < StandardError
31
+ def initialize(step_def_1, step_def_2)
32
+ message = "Multiple step definitions have the same Regexp:\n\n"
33
+ message << step_def_1.to_backtrace_line << "\n"
34
+ message << step_def_2.to_backtrace_line << "\n\n"
35
+ super(message)
36
+ end
37
+ end
38
+
39
+ # This is the main interface for registering step definitions, which is done
40
+ # from <tt>*_steps.rb</tt> files. This module is included right at the top-level
41
+ # so #register_step_definition (and more interestingly - its aliases) are
42
+ # available from the top-level.
43
+ module StepMother
44
+ attr_writer :snippet_generator
45
+ attr_writer :options
46
+
47
+ # Registers a new StepDefinition. This method is aliased
48
+ # to <tt>Given</tt>, <tt>When</tt> and <tt>Then</tt>.
49
+ #
50
+ # See Cucumber#alias_steps for details on how to
51
+ # create your own aliases.
52
+ #
53
+ # The +&proc+ gets executed in the context of a <tt>world</tt>
54
+ # object, which is defined by #World. A new <tt>world</tt>
55
+ # object is created for each scenario and is shared across
56
+ # step definitions within that scenario.
57
+ def register_step_definition(regexp, &proc)
58
+ step_definition = StepDefinition.new(regexp, &proc)
59
+ step_definitions.each do |already|
60
+ raise Redundant.new(already, step_definition) if already.match(regexp)
61
+ end
62
+ step_definitions << step_definition
63
+ step_definition
64
+ end
65
+
66
+ def world(scenario, prior_world = nil, &proc)
67
+ world = prior_world || new_world
68
+ begin
69
+ (@before_procs ||= []).each do |proc|
70
+ world.cucumber_instance_exec(false, 'Before', scenario, &proc)
71
+ end
72
+ yield world
73
+ ensure
74
+ (@after_procs ||= []).each do |proc|
75
+ world.cucumber_instance_exec(false, 'After', scenario, &proc)
76
+ end
77
+ end
78
+ end
79
+
80
+ # Registers a Before proc. You can call this method as many times as you
81
+ # want (typically from ruby scripts under <tt>support</tt>).
82
+ def Before(&proc)
83
+ (@before_procs ||= []) << proc
84
+ end
85
+
86
+ def After(&proc)
87
+ (@after_procs ||= []) << proc
88
+ end
89
+
90
+ # Registers a World proc. You can call this method as many times as you
91
+ # want (typically from ruby scripts under <tt>support</tt>).
92
+ def World(&proc)
93
+ (@world_procs ||= []) << proc
94
+ end
95
+
96
+ # Creates a new world instance
97
+ def new_world #:nodoc:
98
+ world = Object.new
99
+ (@world_procs ||= []).each do |proc|
100
+ world = proc.call(world)
101
+ end
102
+
103
+ world.extend(WorldMethods)
104
+ world.__cucumber_step_mother = self
105
+
106
+ world.extend(::Spec::Matchers) if defined?(::Spec::Matchers)
107
+ world
108
+ end
109
+
110
+ # Looks up the StepDefinition that matches +step_name+
111
+ def step_definition(step_name) #:nodoc:
112
+ found = step_definitions.select do |step_definition|
113
+ step_definition.match(step_name)
114
+ end
115
+ raise Undefined.new(step_name) if found.empty?
116
+ found = best_matches(step_name, found) if found.size > 1 && options[:guess]
117
+ raise Ambiguous.new(step_name, found) if found.size > 1
118
+ found[0]
119
+ end
120
+
121
+ def best_matches(step_name, step_definitions)
122
+ top_group_score = step_definitions.map {|s| s.match(step_name).captures.length }.sort.last
123
+ top_groups = step_definitions.select {|s| s.match(step_name).captures.length == top_group_score }
124
+ if top_groups.size > 1
125
+ shortest_capture_length = top_groups.map {|s| s.match(step_name).captures.inject(0) {|sum, c| sum + c.length } }.sort.first
126
+ top_groups.select {|s| s.match(step_name).captures.inject(0) {|sum, c| sum + c.length } == shortest_capture_length }
127
+ else
128
+ top_groups
129
+ end
130
+ end
131
+
132
+ def step_definitions
133
+ @step_definitions ||= []
134
+ end
135
+
136
+ def snippet_text(step_keyword, step_name)
137
+ @snippet_generator.snippet_text(step_keyword, step_name)
138
+ end
139
+
140
+ def print_step_definitions(out)
141
+ step_definitions.each do |step_definition|
142
+ indent = max_step_definition_length - step_definition.text_length
143
+ out.puts(step_definition.to_s(indent))
144
+ end
145
+ end
146
+
147
+ private
148
+
149
+ def max_step_definition_length
150
+ @max_step_definition_length ||= step_definitions.map{|step_definition| step_definition.text_length}.max
151
+ end
152
+
153
+ def options
154
+ @options || {}
155
+ end
156
+
157
+ module WorldMethods #:nodoc:
158
+ attr_writer :__cucumber_step_mother, :__cucumber_current_step
159
+
160
+ # Call a step from within a step definition
161
+ def __cucumber_invoke(name, *multiline_arguments)
162
+ begin
163
+ # TODO: Very similar to code in Step. Refactor. Get back StepInvocation?
164
+ # Make more similar to JBehave?
165
+ step_definition = @__cucumber_step_mother.step_definition(name)
166
+ matched_args = step_definition.matched_args(name)
167
+ args = (matched_args + multiline_arguments)
168
+ step_definition.execute(name, self, *args)
169
+ rescue Exception => e
170
+ @__cucumber_current_step.exception = e
171
+ raise e
172
+ end
173
+ end
174
+
175
+ def table(text, file=nil, line=0)
176
+ @table_parser ||= Parser::TableParser.new
177
+ @table_parser.parse_or_fail(text.strip, file, line)
178
+ end
179
+
180
+ def pending(message = "TODO")
181
+ if block_given?
182
+ begin
183
+ yield
184
+ rescue Exception => e
185
+ raise Pending.new(message)
186
+ end
187
+ raise Pending.new("Expected pending '#{message}' to fail. No Error was raised. No longer pending?")
188
+ else
189
+ raise Pending.new(message)
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,10 @@
1
+ module Cucumber #:nodoc:
2
+ class VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 99
6
+ PATCH = 23 # Set to nil for official release
7
+
8
+ STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Sets up Cucumber in your Rails project. After running this generator you will
3
+ get a new rake task called features.
4
+
5
+ This also generates the necessary files in the features directory.
6
+
7
+ Also see the feature generator, which you can use to generate skeletons
8
+ for new features.
9
+
10
+ If you set the language option, then a subdirectory features/[language] will be generated instead.
11
+ Now your are able to use features in different languages.
12
+
13
+ Examples:
14
+ `./script/generate cucumber`
@@ -0,0 +1,75 @@
1
+ require "rbconfig"
2
+
3
+ # This generator bootstraps a Rails project for use with Cucumber
4
+ class CucumberGenerator < Rails::Generator::Base
5
+ DEFAULT_SHEBANG = File.join(Config::CONFIG["bindir"],
6
+ Config::CONFIG["ruby_install_name"])
7
+
8
+ attr_reader :language
9
+ attr_accessor :framework
10
+
11
+ def initialize(runtime_args, runtime_options = {})
12
+ super
13
+ @features_path = "features"
14
+ end
15
+
16
+ def manifest
17
+ if options[:language]
18
+ @language = options[:language]
19
+ set_language(@language)
20
+ end
21
+ record do |m|
22
+ m.directory File.join(@features_path, "step_definitions")
23
+ if @language
24
+ m.file File.join(@language, "webrat_steps.rb"), File.join(@features_path, "step_definitions", "paths.rb")
25
+ m.file File.join(@language, "webrat_steps.rb"), File.join(@features_path, "step_definitions", "webrat_steps.rb")
26
+ else
27
+ m.file "webrat_steps.rb", File.join(@features_path, "step_definitions", "webrat_steps.rb")
28
+ m.file "paths.rb", "features/support/paths.rb"
29
+ end
30
+ m.directory "features/support"
31
+ m.file "env.rb", "features/support/env.rb"
32
+
33
+ m.directory "lib/tasks"
34
+ m.template "cucumber.rake", "lib/tasks/cucumber.rake"
35
+
36
+ m.file "cucumber", "script/cucumber", {
37
+ :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
38
+ }
39
+ end
40
+ end
41
+
42
+ def framework
43
+ options[:framework] || :rspec
44
+ end
45
+
46
+ protected
47
+
48
+ def banner
49
+ "Usage: #{$0} cucumber"
50
+ end
51
+
52
+ def add_options!(opt)
53
+ opt.separator ""
54
+ opt.separator "Options:"
55
+ opt.on("-l", "--language=lang", String, "Use a [language] subdirectoy in /features.") { |v| options[:language] = v }
56
+ end
57
+
58
+ # Load up the transations for the passed language, and modify the features_path accordingly
59
+ def set_language(language)
60
+ @features_path = File.join(@features_path, language)
61
+ end
62
+
63
+ def add_options!(opt)
64
+ opt.separator ''
65
+ opt.separator 'Options:'
66
+ opt.on('--rspec', 'Setup cucumber for use with RSpec (default)') do |value|
67
+ options[:framework] = :rspec
68
+ end
69
+
70
+ opt.on('--testunit', 'Setup cucumber for use with test/unit') do |value|
71
+ options[:framework] = :testunit
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
4
+ rescue LoadError => e
5
+ raise unless e.to_s =~ /cucumber/
6
+ require "rubygems"
7
+ load File.join(Gem.bindir, "cucumber")
8
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
2
+
3
+ begin
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:features) do |t|
7
+ <% if language %>
8
+ t.language = "<%= language%>"
9
+ t.cucumber_opts = "--format pretty --language <%= language%>"
10
+ <% else %>
11
+ t.cucumber_opts = "--format pretty"
12
+ <% end %>
13
+ end
14
+ task :features => 'db:test:prepare'
15
+ rescue LoadError
16
+ desc 'Cucumber rake task not available'
17
+ task :features do
18
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] ||= "test"
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
4
+ require 'cucumber/rails/world'
5
+ require 'cucumber/formatters/unicode' # Comment out this line if you don't want Cucumber Unicode support
6
+ Cucumber::Rails.use_transactional_fixtures
7
+
8
+ require 'webrat'
9
+
10
+ Webrat.configure do |config|
11
+ config.mode = :rails
12
+ end
13
+ <% if framework == :rspec -%>
14
+
15
+ require 'cucumber/rails/rspec'
16
+ require 'webrat/core/matchers'
17
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ module NavigationHelpers
2
+ def path_to(page_name)
3
+ case page_name
4
+
5
+ when /the homepage/i
6
+ root_path
7
+
8
+ # Add more page name => path mappings here
9
+
10
+ else
11
+ raise "Can't find mapping from \"#{page_name}\" to a path."
12
+ end
13
+ end
14
+ end
15
+
16
+ World do |world|
17
+ world.extend NavigationHelpers
18
+ world
19
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2
+
3
+ # Commonly used webrat steps
4
+ # http://github.com/brynary/webrat
5
+
6
+ Given /^I am on (.+)$/ do |page_name|
7
+ visit path_to(page_name)
8
+ end
9
+
10
+ When /^I go to (.+)$/ do |page_name|
11
+ visit path_to(page_name)
12
+ end
13
+
14
+ When /^I press "(.*)"$/ do |button|
15
+ click_button(button)
16
+ end
17
+
18
+ When /^I follow "(.*)"$/ do |link|
19
+ click_link(link)
20
+ end
21
+
22
+ When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
23
+ fill_in(field, :with => value)
24
+ end
25
+
26
+ When /^I select "(.*)" from "(.*)"$/ do |value, field|
27
+ select(value, :from => field)
28
+ end
29
+
30
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
31
+ # When I select "December 25, 2008 10:00" as the date and time
32
+ When /^I select "(.*)" as the date and time$/ do |time|
33
+ select_datetime(time)
34
+ end
35
+
36
+ # Use this step when using multiple datetime_select helpers on a page or
37
+ # you want to specify which datetime to select. Given the following view:
38
+ # <%%= f.label :preferred %><br />
39
+ # <%%= f.datetime_select :preferred %>
40
+ # <%%= f.label :alternative %><br />
41
+ # <%%= f.datetime_select :alternative %>
42
+ # The following steps would fill out the form:
43
+ # When I select "November 23, 2004 11:20" as the "Preferred" data and time
44
+ # And I select "November 25, 2004 10:30" as the "Alternative" data and time
45
+ When /^I select "(.*)" as the "(.*)" date and time$/ do |datetime, datetime_label|
46
+ select_datetime(datetime, :from => datetime_label)
47
+ end
48
+
49
+ # Use this step in conjunction with Rail's time_select helper. For example:
50
+ # When I select "2:20PM" as the time
51
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
52
+ # will convert the 2:20PM to 14:20 and then select it.
53
+ When /^I select "(.*)" as the time$/ do |time|
54
+ select_time(time)
55
+ end
56
+
57
+ # Use this step when using multiple time_select helpers on a page or you want to
58
+ # specify the name of the time on the form. For example:
59
+ # When I select "7:30AM" as the "Gym" time
60
+ When /^I select "(.*)" as the "(.*)" time$/ do |time, time_label|
61
+ select_time(time, :from => time_label)
62
+ end
63
+
64
+ # Use this step in conjunction with Rail's date_select helper. For example:
65
+ # When I select "February 20, 1981" as the date
66
+ When /^I select "(.*)" as the date$/ do |date|
67
+ select_date(date)
68
+ end
69
+
70
+ # Use this step when using multiple date_select helpers on one page or
71
+ # you want to specify the name of the date on the form. For example:
72
+ # When I select "April 26, 1982" as the "Date of Birth" date
73
+ When /^I select "(.*)" as the "(.*)" date$/ do |date, date_label|
74
+ select_date(date, :from => date_label)
75
+ end
76
+
77
+ When /^I check "(.*)"$/ do |field|
78
+ check(field)
79
+ end
80
+
81
+ When /^I uncheck "(.*)"$/ do |field|
82
+ uncheck(field)
83
+ end
84
+
85
+ When /^I choose "(.*)"$/ do |field|
86
+ choose(field)
87
+ end
88
+
89
+ When /^I attach the file at "(.*)" to "(.*)"$/ do |path, field|
90
+ attach_file(field, path)
91
+ end
92
+
93
+ Then /^I should see "(.*)"$/ do |text|
94
+ <% if framework == :rspec -%>
95
+ response.should contain(text)
96
+ <% else -%>
97
+ assert_contain text
98
+ <% end -%>
99
+ end
100
+
101
+ Then /^I should not see "(.*)"$/ do |text|
102
+ <% if framework == :rspec -%>
103
+ response.should_not contain(text)
104
+ <% else -%>
105
+ assert_not_contain text
106
+ <% end -%>
107
+ end
108
+
109
+ Then /^the "(.*)" checkbox should be checked$/ do |label|
110
+ <% if framework == :rspec -%>
111
+ field_labeled(label).should be_checked
112
+ <% else -%>
113
+ assert field_labeled(label).checked?
114
+ <% end -%>
115
+ end