cucumber 3.0.0.pre.1 → 3.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (316) hide show
  1. checksums.yaml +4 -4
  2. data/.cucumberproignore +6 -0
  3. data/.rubocop.yml +13 -0
  4. data/.rubocop_todo.yml +1075 -0
  5. data/.travis.yml +42 -8
  6. data/CONTRIBUTING.md +8 -1
  7. data/Gemfile +16 -10
  8. data/History.md +96 -36
  9. data/README.md +12 -3
  10. data/Rakefile +12 -2
  11. data/appveyor.yml +26 -0
  12. data/cucumber.gemspec +15 -10
  13. data/cucumber.yml +9 -10
  14. data/examples/i18n/Rakefile +1 -1
  15. data/examples/i18n/ar/features/step_definitions/calculator_steps.rb +2 -2
  16. data/examples/i18n/ar/lib/calculator.rb +2 -2
  17. data/examples/i18n/bg/features/step_definitions/calculator_steps.rb +6 -6
  18. data/examples/i18n/ca/features/step_definitions/calculator_steps.rb +4 -4
  19. data/examples/i18n/ca/lib/calculadora.rb +2 -2
  20. data/examples/i18n/cs/features/step_definitions/calculator_steps.rb +4 -4
  21. data/examples/i18n/cs/lib/calculator.rb +3 -3
  22. data/examples/i18n/da/features/step_definitions/lommeregner_steps.rb +4 -4
  23. data/examples/i18n/da/lib/lommeregner.rb +2 -2
  24. data/examples/i18n/de/features/step_definitions/calculator_steps.rb +4 -4
  25. data/examples/i18n/de/lib/calculator.rb +2 -2
  26. data/examples/i18n/el/features/step_definitions/calculator_steps.rb +5 -5
  27. data/examples/i18n/el/lib/calculator.rb +2 -2
  28. data/examples/i18n/en-lol/features/step_definitions/cucumbrz_steps.rb +4 -4
  29. data/examples/i18n/en-lol/lib/basket.rb +2 -2
  30. data/examples/i18n/en-lol/lib/belly.rb +2 -2
  31. data/examples/i18n/en/features/step_definitions/calculator_steps.rb +4 -4
  32. data/examples/i18n/en/lib/calculator.rb +2 -2
  33. data/examples/i18n/eo/features/step_definitions/calculator_steps.rb +4 -4
  34. data/examples/i18n/eo/lib/calculator.rb +2 -2
  35. data/examples/i18n/es/features/step_definitions/calculador_steps.rb +5 -5
  36. data/examples/i18n/es/lib/calculador.rb +2 -2
  37. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +4 -4
  38. data/examples/i18n/et/lib/kalkulaator.rb +3 -3
  39. data/examples/i18n/fi/features/step_definitions/laskin_steps.rb +3 -3
  40. data/examples/i18n/fi/lib/laskin.rb +1 -1
  41. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +8 -8
  42. data/examples/i18n/fr/features/support/env.rb +1 -1
  43. data/examples/i18n/fr/lib/calculatrice.rb +2 -2
  44. data/examples/i18n/he/features/step_definitions/calculator_steps.rb +4 -4
  45. data/examples/i18n/he/lib/calculator.rb +1 -1
  46. data/examples/i18n/hi/features/step_definitions/calculator_steps.rb +3 -3
  47. data/examples/i18n/hi/lib/calculator.rb +1 -1
  48. data/examples/i18n/ht/features/step_definitions/kalkilatris_steps.rb +4 -4
  49. data/examples/i18n/ht/lib/kalkilatris.rb +2 -2
  50. data/examples/i18n/hu/features/step_definitions/calculator_steps.rb +4 -4
  51. data/examples/i18n/hu/lib/calculator.rb +1 -1
  52. data/examples/i18n/id/features/step_definitions/calculator_steps.rb +4 -4
  53. data/examples/i18n/id/lib/calculator.rb +2 -2
  54. data/examples/i18n/it/features/step_definitions/calcolatrice_steps.rb +4 -4
  55. data/examples/i18n/it/lib/calcolatrice.rb +3 -3
  56. data/examples/i18n/ja/features/step_definitions/calculator_steps.rb +3 -3
  57. data/examples/i18n/ja/features/support/env.rb +1 -1
  58. data/examples/i18n/ja/lib/calculator.rb +2 -2
  59. data/examples/i18n/ko/features/step_definitions/calculator_steps.rb +4 -4
  60. data/examples/i18n/ko/lib/calculator.rb +2 -2
  61. data/examples/i18n/lt/features/step_definitions/calculator_steps.rb +4 -4
  62. data/examples/i18n/lt/lib/calculator.rb +2 -2
  63. data/examples/i18n/lv/features/step_definitions/calculator_steps.rb +4 -4
  64. data/examples/i18n/lv/lib/calculator.rb +2 -2
  65. data/examples/i18n/no/features/step_definitions/kalkulator_steps.rb +3 -3
  66. data/examples/i18n/no/features/support/env.rb +1 -1
  67. data/examples/i18n/no/lib/kalkulator.rb +2 -2
  68. data/examples/i18n/pl/features/step_definitions/calculator_steps.rb +4 -4
  69. data/examples/i18n/pl/lib/calculator.rb +2 -2
  70. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +3 -3
  71. data/examples/i18n/pt/features/support/env.rb +1 -1
  72. data/examples/i18n/pt/lib/calculadora.rb +1 -1
  73. data/examples/i18n/ro/features/step_definitions/calculator_steps.rb +5 -5
  74. data/examples/i18n/ro/lib/calculator.rb +1 -1
  75. data/examples/i18n/ru/features/step_definitions/calculator_steps.rb +5 -5
  76. data/examples/i18n/sk/features/step_definitions/calculator_steps.rb +4 -4
  77. data/examples/i18n/sk/lib/calculator.rb +2 -2
  78. data/examples/i18n/sr-Cyrl/features/step_definitions/calculator_steps.rb +3 -3
  79. data/examples/i18n/sr-Cyrl/features/support/env.rb +1 -1
  80. data/examples/i18n/sr-Cyrl/lib/calculator.rb +2 -2
  81. data/examples/i18n/sr-Latn/features/step_definitions/calculator_steps.rb +4 -4
  82. data/examples/i18n/sr-Latn/lib/calculator.rb +2 -2
  83. data/examples/i18n/sv/features/step_definitions/kalkulator_steps.rb +3 -3
  84. data/examples/i18n/sv/lib/kalkulator.rb +2 -2
  85. data/examples/i18n/tr/features/step_definitions/hesap_makinesi_adimlari.rb +4 -4
  86. data/examples/i18n/tr/lib/hesap_makinesi.rb +2 -2
  87. data/examples/i18n/uk/features/step_definitions/calculator_steps.rb +4 -4
  88. data/examples/i18n/uz/features/step_definitions/calculator_steps.rb +4 -4
  89. data/examples/i18n/zh-CN/features/step_definitions/calculator_steps.rb +5 -5
  90. data/examples/i18n/zh-CN/lib/calculator.rb +2 -2
  91. data/examples/i18n/zh-TW/features/step_definitions/calculator_steps.rb +4 -4
  92. data/examples/i18n/zh-TW/lib/calculator.rb +2 -2
  93. data/examples/rspec_doubles/features/step_definitions/calvin_steps.rb +3 -3
  94. data/examples/sinatra/features/step_definitions/add_steps.rb +4 -4
  95. data/examples/tcl/features/step_definitions/fib_steps.rb +2 -2
  96. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +4 -4
  97. data/examples/watir/features/step_definitions/search_steps.rb +3 -3
  98. data/examples/watir/features/support/screenshots.rb +5 -5
  99. data/features/docs/api/list_step_defs_as_json.feature +21 -7
  100. data/features/docs/api/listen_for_events.feature +1 -1
  101. data/features/docs/api/run_cli_main_with_existing_runtime.feature +1 -0
  102. data/features/docs/cli/dry_run.feature +3 -0
  103. data/features/docs/cli/execute_with_tag_filter.feature +4 -4
  104. data/features/docs/cli/fail_fast.feature +2 -0
  105. data/features/docs/{gherkin/language_help.feature → cli/i18n.feature} +6 -6
  106. data/features/docs/cli/randomize.feature +2 -2
  107. data/features/docs/cli/retry_failing_tests.feature +28 -3
  108. data/features/docs/cli/run_scenarios_matching_name.feature +1 -0
  109. data/features/docs/cli/specifying_multiple_formatters.feature +3 -0
  110. data/features/docs/cli/strict_mode.feature +6 -0
  111. data/features/docs/defining_steps/nested_steps.feature +5 -1
  112. data/features/docs/defining_steps/nested_steps_i18n.feature +1 -0
  113. data/features/docs/defining_steps/nested_steps_with_second_arg.feature +2 -0
  114. data/features/docs/defining_steps/printing_messages.feature +1 -1
  115. data/features/docs/defining_steps/skip_scenario.feature +1 -0
  116. data/features/docs/defining_steps/snippets.feature +18 -18
  117. data/features/docs/events/gherkin_source_read_event.feature +43 -0
  118. data/features/docs/events/step_activated_event.feature +36 -0
  119. data/features/docs/events/step_definition_registered_event.feature +29 -0
  120. data/features/docs/events/test_case_finished_event.feature +35 -0
  121. data/features/docs/events/test_case_starting_event.feature +54 -0
  122. data/features/docs/events/test_run_finished_event.feature +40 -0
  123. data/features/docs/events/test_run_starting_event.feature +41 -0
  124. data/features/docs/events/test_step_finished_event.feature +47 -0
  125. data/features/docs/events/test_step_starting_event.feature +43 -0
  126. data/features/docs/exception_in_after_hook.feature +3 -2
  127. data/features/docs/exception_in_after_step_hook.feature +2 -0
  128. data/features/docs/exception_in_around_hook.feature +2 -0
  129. data/features/docs/exception_in_before_hook.feature +3 -1
  130. data/features/docs/extending_cucumber/custom_formatter.feature +21 -1
  131. data/features/docs/formatters/json_formatter.feature +4 -4
  132. data/features/docs/formatters/junit_formatter.feature +7 -6
  133. data/features/docs/formatters/pretty_formatter.feature +1 -0
  134. data/features/docs/formatters/progress_formatter.feature +1 -0
  135. data/features/docs/formatters/rerun_formatter.feature +2 -0
  136. data/features/docs/formatters/summary_formatter.feature +1 -0
  137. data/features/docs/formatters/usage_formatter.feature +3 -0
  138. data/features/docs/getting_started.feature +2 -1
  139. data/features/docs/gherkin/background.feature +5 -5
  140. data/features/docs/gherkin/doc_strings.feature +2 -0
  141. data/features/docs/gherkin/expand_option_for_outlines.feature +1 -0
  142. data/features/docs/gherkin/outlines.feature +4 -0
  143. data/features/docs/gherkin/unicode_table.feature +1 -0
  144. data/features/docs/gherkin/using_descriptions.feature +1 -0
  145. data/features/docs/gherkin/using_star_notation.feature +1 -1
  146. data/features/docs/post_configuration_hook.feature +1 -1
  147. data/features/docs/rake_task.feature +5 -0
  148. data/features/docs/raketask.feature +3 -1
  149. data/features/docs/work_in_progress.feature +5 -2
  150. data/features/docs/writing_support_code/after_step_hooks.feature +3 -1
  151. data/features/docs/writing_support_code/around_hooks.feature +6 -0
  152. data/features/docs/writing_support_code/before_hook.feature +1 -0
  153. data/features/docs/writing_support_code/hook_order.feature +3 -1
  154. data/features/docs/writing_support_code/parameter_types.feature +75 -0
  155. data/features/docs/writing_support_code/tagged_hooks.feature +1 -1
  156. data/features/lib/step_definitions/aruba_steps.rb +4 -10
  157. data/features/lib/step_definitions/cli_steps.rb +2 -2
  158. data/features/lib/step_definitions/cucumber_steps.rb +8 -12
  159. data/features/lib/step_definitions/iso-8859-1_steps.rb +2 -2
  160. data/features/lib/step_definitions/json_steps.rb +1 -1
  161. data/features/lib/step_definitions/junit_steps.rb +1 -1
  162. data/features/lib/step_definitions/language_steps.rb +2 -2
  163. data/features/lib/step_definitions/profile_steps.rb +6 -6
  164. data/features/lib/step_definitions/retry_steps.rb +3 -3
  165. data/features/lib/step_definitions/ruby_steps.rb +1 -1
  166. data/features/lib/support/env.rb +1 -1
  167. data/features/lib/support/fake_wire_server.rb +7 -2
  168. data/features/lib/support/feature_factory.rb +1 -1
  169. data/features/lib/support/normalise_output.rb +13 -12
  170. data/features/lib/support/parameter_types.rb +8 -0
  171. data/gem_tasks/contributors.rake +9 -6
  172. data/gem_tasks/environment.rake +1 -5
  173. data/gem_tasks/examples.rake +1 -1
  174. data/gem_tasks/fix_cr_lf.rake +1 -1
  175. data/gem_tasks/flog.rake +2 -2
  176. data/gem_tasks/rspec.rake +1 -1
  177. data/lib/autotest/cucumber_mixin.rb +15 -15
  178. data/lib/autotest/discover.rb +2 -2
  179. data/lib/cucumber/cli/configuration.rb +7 -13
  180. data/lib/cucumber/cli/main.rb +6 -6
  181. data/lib/cucumber/cli/options.rb +163 -126
  182. data/lib/cucumber/cli/profile_loader.rb +24 -20
  183. data/lib/cucumber/configuration.rb +12 -17
  184. data/lib/cucumber/constantize.rb +1 -1
  185. data/lib/cucumber/core_ext/string.rb +1 -1
  186. data/lib/cucumber/deprecate.rb +1 -1
  187. data/lib/cucumber/events.rb +11 -1
  188. data/lib/cucumber/events/gherkin_source_read.rb +17 -0
  189. data/lib/cucumber/events/{step_match.rb → step_activated.rb} +2 -2
  190. data/lib/cucumber/events/step_definition_registered.rb +1 -1
  191. data/lib/cucumber/events/test_case_finished.rb +18 -0
  192. data/lib/cucumber/events/test_case_starting.rb +15 -0
  193. data/lib/cucumber/events/test_run_starting.rb +16 -0
  194. data/lib/cucumber/events/test_step_finished.rb +20 -0
  195. data/lib/cucumber/events/test_step_starting.rb +17 -0
  196. data/lib/cucumber/filters.rb +1 -0
  197. data/lib/cucumber/filters/activate_steps.rb +1 -1
  198. data/lib/cucumber/filters/broadcast_test_run_starting_event.rb +27 -0
  199. data/lib/cucumber/filters/retry.rb +1 -1
  200. data/lib/cucumber/filters/tag_limits.rb +3 -3
  201. data/lib/cucumber/filters/tag_limits/verifier.rb +1 -1
  202. data/lib/cucumber/formatter/ansicolor.rb +8 -11
  203. data/lib/cucumber/formatter/backtrace_filter.rb +19 -7
  204. data/lib/cucumber/formatter/console.rb +16 -19
  205. data/lib/cucumber/formatter/console_counts.rb +8 -21
  206. data/lib/cucumber/formatter/console_issues.rb +30 -9
  207. data/lib/cucumber/formatter/duration.rb +1 -1
  208. data/lib/cucumber/formatter/fail_fast.rb +1 -1
  209. data/lib/cucumber/formatter/html.rb +168 -242
  210. data/lib/cucumber/formatter/html_builder.rb +110 -0
  211. data/lib/cucumber/formatter/inline-js.js +30 -0
  212. data/lib/cucumber/formatter/interceptor.rb +2 -2
  213. data/lib/cucumber/formatter/json.rb +12 -12
  214. data/lib/cucumber/formatter/junit.rb +11 -11
  215. data/lib/cucumber/formatter/legacy_api/adapter.rb +27 -27
  216. data/lib/cucumber/formatter/legacy_api/ast.rb +16 -20
  217. data/lib/cucumber/formatter/legacy_api/results.rb +6 -8
  218. data/lib/cucumber/formatter/pretty.rb +17 -17
  219. data/lib/cucumber/formatter/progress.rb +11 -12
  220. data/lib/cucumber/formatter/rerun.rb +1 -1
  221. data/lib/cucumber/formatter/steps.rb +1 -1
  222. data/lib/cucumber/formatter/unicode.rb +1 -1
  223. data/lib/cucumber/formatter/usage.rb +12 -12
  224. data/lib/cucumber/gherkin/formatter/ansi_escapes.rb +1 -1
  225. data/lib/cucumber/gherkin/formatter/escaping.rb +1 -1
  226. data/lib/cucumber/{rb_support/rb_dsl.rb → glue/dsl.rb} +44 -17
  227. data/lib/cucumber/glue/hook.rb +43 -0
  228. data/lib/cucumber/glue/invoke_in_world.rb +70 -0
  229. data/lib/cucumber/glue/proto_world.rb +225 -0
  230. data/lib/cucumber/{rb_support/rb_language.rb → glue/registry_and_more.rb} +45 -86
  231. data/lib/cucumber/{rb_support → glue}/snippet.rb +62 -25
  232. data/lib/cucumber/glue/step_definition.rb +143 -0
  233. data/lib/cucumber/glue/world_factory.rb +23 -0
  234. data/lib/cucumber/hooks.rb +4 -4
  235. data/lib/cucumber/multiline_argument.rb +2 -2
  236. data/lib/cucumber/multiline_argument/data_table.rb +40 -178
  237. data/lib/cucumber/multiline_argument/data_table/diff_matrices.rb +158 -0
  238. data/lib/cucumber/platform.rb +3 -5
  239. data/lib/cucumber/rake/task.rb +11 -11
  240. data/lib/cucumber/rspec/disable_option_parser.rb +1 -1
  241. data/lib/cucumber/rspec/doubles.rb +1 -1
  242. data/lib/cucumber/running_test_case.rb +2 -2
  243. data/lib/cucumber/runtime.rb +46 -34
  244. data/lib/cucumber/runtime/after_hooks.rb +1 -1
  245. data/lib/cucumber/runtime/for_programming_languages.rb +1 -36
  246. data/lib/cucumber/runtime/support_code.rb +19 -15
  247. data/lib/cucumber/runtime/user_interface.rb +4 -11
  248. data/lib/cucumber/step_argument.rb +0 -2
  249. data/lib/cucumber/step_definition_light.rb +1 -0
  250. data/lib/cucumber/step_match.rb +16 -15
  251. data/lib/cucumber/step_match_search.rb +2 -3
  252. data/lib/cucumber/term/ansicolor.rb +1 -1
  253. data/lib/cucumber/version +1 -1
  254. data/lib/simplecov_setup.rb +1 -1
  255. data/scripts/invite-collaborator +40 -0
  256. data/scripts/update-history +83 -0
  257. data/spec/cucumber/cli/configuration_spec.rb +95 -97
  258. data/spec/cucumber/cli/main_spec.rb +7 -7
  259. data/spec/cucumber/cli/options_spec.rb +112 -78
  260. data/spec/cucumber/cli/profile_loader_spec.rb +24 -5
  261. data/spec/cucumber/cli/rerun_spec.rb +20 -20
  262. data/spec/cucumber/configuration_spec.rb +47 -47
  263. data/spec/cucumber/constantize_spec.rb +2 -2
  264. data/spec/cucumber/events_spec.rb +9 -0
  265. data/spec/cucumber/file_specs_spec.rb +25 -25
  266. data/spec/cucumber/filters/activate_steps_spec.rb +16 -16
  267. data/spec/cucumber/filters/gated_receiver_spec.rb +6 -6
  268. data/spec/cucumber/filters/retry_spec.rb +22 -9
  269. data/spec/cucumber/filters/tag_limits/test_case_index_spec.rb +11 -11
  270. data/spec/cucumber/filters/tag_limits/verifier_spec.rb +14 -14
  271. data/spec/cucumber/filters/tag_limits_spec.rb +8 -8
  272. data/spec/cucumber/formatter/ansicolor_spec.rb +9 -9
  273. data/spec/cucumber/formatter/backtrace_filter_spec.rb +32 -0
  274. data/spec/cucumber/formatter/console_counts_spec.rb +1 -1
  275. data/spec/cucumber/formatter/duration_spec.rb +3 -3
  276. data/spec/cucumber/formatter/fail_fast_spec.rb +21 -21
  277. data/spec/cucumber/formatter/html_spec.rb +58 -58
  278. data/spec/cucumber/formatter/json_spec.rb +44 -46
  279. data/spec/cucumber/formatter/junit_spec.rb +43 -45
  280. data/spec/cucumber/formatter/legacy_api/adapter_spec.rb +43 -43
  281. data/spec/cucumber/formatter/pretty_spec.rb +107 -107
  282. data/spec/cucumber/formatter/progress_spec.rb +20 -20
  283. data/spec/cucumber/formatter/rerun_spec.rb +1 -1
  284. data/spec/cucumber/formatter/spec_helper.rb +6 -5
  285. data/spec/cucumber/{rb_support/rb_world_spec.rb → glue/proto_world_spec.rb} +20 -5
  286. data/spec/cucumber/glue/registry_and_more_spec.rb +213 -0
  287. data/spec/cucumber/{rb_support → glue}/snippet_spec.rb +61 -25
  288. data/spec/cucumber/glue/step_definition_spec.rb +207 -0
  289. data/spec/cucumber/hooks_spec.rb +3 -3
  290. data/spec/cucumber/multiline_argument/data_table_spec.rb +177 -133
  291. data/spec/cucumber/project_initializer_spec.rb +10 -10
  292. data/spec/cucumber/rake/forked_spec.rb +10 -10
  293. data/spec/cucumber/rake/task_spec.rb +20 -20
  294. data/spec/cucumber/running_test_case_spec.rb +35 -35
  295. data/spec/cucumber/runtime/for_programming_languages_spec.rb +1 -30
  296. data/spec/cucumber/runtime_spec.rb +2 -2
  297. data/spec/cucumber/step_argument_spec.rb +5 -5
  298. data/spec/cucumber/step_match_search_spec.rb +31 -41
  299. data/spec/cucumber/step_match_spec.rb +33 -33
  300. data/spec/cucumber/world/pending_spec.rb +10 -10
  301. metadata +117 -47
  302. data/features/docs/formatters/debug_formatter.feature +0 -47
  303. data/features/docs/writing_support_code/transforms.feature +0 -98
  304. data/features/lib/step_definitions/wire_steps.rb +0 -59
  305. data/gem_tasks/cucumber.rake +0 -26
  306. data/lib/cucumber/core_ext/instance_exec.rb +0 -71
  307. data/lib/cucumber/formatter/debug.rb +0 -36
  308. data/lib/cucumber/rb_support/rb_hook.rb +0 -20
  309. data/lib/cucumber/rb_support/rb_step_definition.rb +0 -132
  310. data/lib/cucumber/rb_support/rb_transform.rb +0 -60
  311. data/lib/cucumber/rb_support/rb_world.rb +0 -171
  312. data/spec/cucumber/core_ext/instance_exec_spec.rb +0 -5
  313. data/spec/cucumber/formatter/debug_spec.rb +0 -65
  314. data/spec/cucumber/rb_support/rb_language_spec.rb +0 -321
  315. data/spec/cucumber/rb_support/rb_step_definition_spec.rb +0 -200
  316. data/spec/cucumber/rb_support/rb_transform_spec.rb +0 -47
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require 'cucumber/glue/invoke_in_world'
3
+
4
+ module Cucumber
5
+ module Glue
6
+ # TODO: Kill pointless wrapper for Before, After and AfterStep hooks with fire
7
+ class Hook
8
+ attr_reader :tag_expressions, :location
9
+
10
+ def initialize(registry, tag_expressions, proc)
11
+ @registry = registry
12
+ @tag_expressions = tag_expressions
13
+ @proc = proc
14
+ @location = Cucumber::Core::Ast::Location.from_source_location(*@proc.source_location)
15
+ warn_for_old_style_tag_expressions(tag_expressions)
16
+ end
17
+
18
+ def invoke(pseudo_method, arguments, &block)
19
+ check_arity = false
20
+ InvokeInWorld.cucumber_instance_exec_in(
21
+ @registry.current_world,
22
+ check_arity,
23
+ pseudo_method,
24
+ *[arguments, block].flatten.compact,
25
+ &@proc
26
+ )
27
+ end
28
+
29
+ private
30
+
31
+ def warn_for_old_style_tag_expressions(tag_expressions)
32
+ tag_expressions.each do |tag_expression|
33
+ if tag_expression.include?('~') && tag_expression != '~@no-clobber' # ~@no-clobber is used in aruba
34
+ warn("Deprecated: Found tagged hook with '#{tag_expression}'. Support for '~@tag' will be removed from the next release of Cucumber. Please use 'not @tag' instead.")
35
+ end
36
+ if tag_expression.include?(',')
37
+ warn("Deprecated: Found tagged hook with '#{tag_expression}'. Support for '@tag1,@tag2' will be removed from the next release of Cucumber. Please use '@tag or @tag2' instead.")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+ require 'cucumber/platform'
3
+ module Cucumber
4
+ module Glue
5
+ # Utility methods for executing step definitions with nice backtraces etc.
6
+ # TODO: add unit tests
7
+ # TODO: refactor for readability
8
+ class InvokeInWorld
9
+ def self.replace_instance_exec_invocation_line!(backtrace, instance_exec_invocation_line, pseudo_method)
10
+ return if Cucumber.use_full_backtrace
11
+
12
+ instance_exec_pos = backtrace.index(instance_exec_invocation_line)
13
+ if instance_exec_pos
14
+ replacement_line = instance_exec_pos + INSTANCE_EXEC_OFFSET
15
+ backtrace[replacement_line].gsub!(/`.*'/, "`#{pseudo_method}'") if pseudo_method
16
+
17
+ depth = backtrace.count { |line| line == instance_exec_invocation_line }
18
+ end_pos = depth > 1 ? instance_exec_pos : -1
19
+
20
+ backtrace[replacement_line+1..end_pos] = nil
21
+ backtrace.compact!
22
+ end
23
+ end
24
+
25
+ def self.cucumber_instance_exec_in(world, check_arity, pseudo_method, *args, &block)
26
+ cucumber_run_with_backtrace_filtering(pseudo_method) do
27
+ if check_arity && !cucumber_compatible_arity?(args, block)
28
+ world.instance_exec do
29
+ ari = block.arity
30
+ ari = ari < 0 ? (ari.abs-1).to_s+'+' : ari
31
+ s1 = ari == 1 ? '' : 's'
32
+ s2 = args.length == 1 ? '' : 's'
33
+ raise ArityMismatchError.new(
34
+ "Your block takes #{ari} argument#{s1}, but the Regexp matched #{args.length} argument#{s2}."
35
+ )
36
+ end
37
+ else
38
+ world.instance_exec(*args, &block)
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.cucumber_compatible_arity?(args, block)
44
+ return true if block.arity == args.length
45
+ if block.arity < 0
46
+ return true if args.length >= (block.arity.abs - 1)
47
+ end
48
+ false
49
+ end
50
+
51
+ def self.cucumber_run_with_backtrace_filtering(pseudo_method)
52
+ begin
53
+ yield
54
+ rescue Exception => e
55
+ instance_exec_invocation_line = "#{__FILE__}:#{__LINE__ - 2}:in `cucumber_run_with_backtrace_filtering'"
56
+ replace_instance_exec_invocation_line!((e.backtrace || []), instance_exec_invocation_line, pseudo_method)
57
+ raise e
58
+ end
59
+ end
60
+
61
+ INSTANCE_EXEC_OFFSET = -3
62
+ end
63
+
64
+ # Raised if the number of a StepDefinition's Regexp match groups
65
+ # is different from the number of Proc arguments.
66
+ class ArityMismatchError < StandardError
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+ require 'cucumber/gherkin/formatter/ansi_escapes'
3
+ require 'cucumber/core/ast/data_table'
4
+
5
+ module Cucumber
6
+ module Glue
7
+ # Defines the basic API methods availlable in all Cucumber step definitions.
8
+ #
9
+ # You can, and probably should, extend this API with your own methods that
10
+ # make sense in your domain. For more on that, see {Cucumber::Glue::Dsl#World}
11
+ module ProtoWorld
12
+
13
+ # Call a Transform with a string from another Transform definition
14
+ def Transform(arg)
15
+ super
16
+ end
17
+
18
+ # Run a single Gherkin step
19
+ # @example Call another step
20
+ # step "I am logged in"
21
+ # @example Call a step with quotes in the name
22
+ # step %{the user "Dave" is logged in}
23
+ # @example Passing a table
24
+ # step "the following users exist:", table(%{
25
+ # | name | email |
26
+ # | Matt | matt@matt.com |
27
+ # | Aslak | aslak@aslak.com |
28
+ # })
29
+ # @example Passing a multiline string
30
+ # step "the email should contain:", "Dear sir,\nYou've won a prize!\n"
31
+ # @param [String] name The name of the step
32
+ # @param [String,Cucumber::Ast::DocString,Cucumber::Ast::Table] multiline_argument
33
+ def step(name, raw_multiline_arg=nil)
34
+ super
35
+ end
36
+
37
+ # Run a snippet of Gherkin
38
+ # @example
39
+ # steps %{
40
+ # Given the user "Susan" exists
41
+ # And I am logged in as "Susan"
42
+ # }
43
+ # @param [String] steps_text The Gherkin snippet to run
44
+ def steps(steps_text)
45
+ super
46
+ end
47
+
48
+ # Parse Gherkin into a {Cucumber::Ast::Table} object.
49
+ #
50
+ # Useful in conjunction with the #step method.
51
+ # @example Create a table
52
+ # users = table(%{
53
+ # | name | email |
54
+ # | Matt | matt@matt.com |
55
+ # | Aslak | aslak@aslak.com |
56
+ # })
57
+ # @param [String] text_or_table The Gherkin string that represents the table
58
+ # Returns a Cucumber::MultilineArgument::DataTable for +text_or_table+, which can either
59
+ # be a String:
60
+ #
61
+ # table(%{
62
+ # | account | description | amount |
63
+ # | INT-100 | Taxi | 114 |
64
+ # | CUC-101 | Peeler | 22 |
65
+ # })
66
+ #
67
+ # or a 2D Array:
68
+ #
69
+ # table([
70
+ # %w{ account description amount },
71
+ # %w{ INT-100 Taxi 114 },
72
+ # %w{ CUC-101 Peeler 22 }
73
+ # ])
74
+ #
75
+ def table(text_or_table, file=nil, line=0)
76
+ location = !file ? Core::Ast::Location.of_caller : Core::Ast::Location.new(file, line)
77
+ MultilineArgument::DataTable.from(text_or_table, location)
78
+ end
79
+
80
+ # Print a message to the output.
81
+ #
82
+ # @note Cucumber might surprise you with the behaviour of this method. Instead
83
+ # of sending the output directly to STDOUT, Cucumber will intercept and cache
84
+ # the message until the current step has finished, and then display it.
85
+ #
86
+ # If you'd prefer to see the message immediately, call {Kernel.puts} instead.
87
+ def puts(*messages)
88
+ super
89
+ end
90
+
91
+ # Pause the tests and ask the operator for input
92
+ def ask(question, timeout_seconds=60)
93
+ super
94
+ end
95
+
96
+ # Embed an image in the output
97
+ def embed(file, mime_type, label='Screenshot')
98
+ super
99
+ end
100
+
101
+ # Mark the matched step as pending.
102
+ def pending(message = 'TODO')
103
+ if block_given?
104
+ begin
105
+ yield
106
+ rescue Exception
107
+ raise Pending, message
108
+ end
109
+ raise Pending, "Expected pending '#{message}' to fail. No Error was raised. No longer pending?"
110
+ else
111
+ raise Pending, message
112
+ end
113
+ end
114
+
115
+ # Skips this step and the remaining steps in the scenario
116
+ def skip_this_scenario(message = 'Scenario skipped')
117
+ raise Core::Test::Result::Skipped, message
118
+ end
119
+
120
+ # Prints the list of modules that are included in the World
121
+ def inspect
122
+ super
123
+ end
124
+
125
+ # see {#inspect}
126
+ def to_s
127
+ inspect
128
+ end
129
+
130
+ # Dynamially generate the API module, closuring the dependencies
131
+ def self.for(runtime, language)
132
+ Module.new do
133
+ def self.extended(object)
134
+ # wrap the dynamically generated module so that we can document the methods
135
+ # for yardoc, which doesn't like define_method.
136
+ object.extend(ProtoWorld)
137
+ end
138
+
139
+ # TODO: pass these in when building the module, instead of mutating them later
140
+ # Extend the World with user-defined modules
141
+ def add_modules!(world_modules, namespaced_world_modules)
142
+ add_world_modules!(world_modules)
143
+ add_namespaced_modules!(namespaced_world_modules)
144
+ end
145
+
146
+ define_method(:step) do |name, raw_multiline_arg=nil|
147
+ location = Core::Ast::Location.of_caller
148
+ runtime.invoke_dynamic_step(name, MultilineArgument.from(raw_multiline_arg, location))
149
+ end
150
+
151
+ define_method(:steps) do |steps_text|
152
+ location = Core::Ast::Location.of_caller
153
+ runtime.invoke_dynamic_steps(steps_text, language, location)
154
+ end
155
+
156
+ define_method(:puts) do |*messages|
157
+ # Even though they won't be output until later, converting the messages to
158
+ # strings right away will protect them from modifications to their original
159
+ # objects in the mean time
160
+ messages.collect! { |message| "#{message}" }
161
+
162
+ runtime.puts(*messages)
163
+ end
164
+
165
+ define_method(:ask) do |question, timeout_seconds=60|
166
+ runtime.ask(question, timeout_seconds)
167
+ end
168
+
169
+ define_method(:embed) do |file, mime_type, label='Screenshot'|
170
+ runtime.embed(file, mime_type, label)
171
+ end
172
+
173
+ # Prints the list of modules that are included in the World
174
+ def inspect
175
+ modules = [self.class]
176
+ (class << self; self; end).instance_eval do
177
+ modules += included_modules
178
+ end
179
+ modules << stringify_namespaced_modules
180
+ format('#<%s:0x%x>', modules.join('+'), self.object_id)
181
+ end
182
+
183
+ private
184
+
185
+ # @private
186
+ def add_world_modules!(modules)
187
+ modules.each do |world_module|
188
+ extend(world_module)
189
+ end
190
+ end
191
+
192
+ # @private
193
+ def add_namespaced_modules!(modules)
194
+ @__namespaced_modules = modules
195
+ modules.each do |namespace, world_modules|
196
+ world_modules.each do |world_module|
197
+ variable_name = "@__#{namespace}_world"
198
+
199
+ inner_world = if self.class.respond_to?(namespace)
200
+ instance_variable_get(variable_name)
201
+ else
202
+ Object.new
203
+ end
204
+ instance_variable_set(variable_name,
205
+ inner_world.extend(world_module))
206
+ self.class.send(:define_method, namespace) do
207
+ instance_variable_get(variable_name)
208
+ end
209
+ end
210
+ end
211
+ end
212
+
213
+ # @private
214
+ def stringify_namespaced_modules
215
+ @__namespaced_modules.map { |k, v| "#{v.join(',')} (as #{k})" }.join('+')
216
+ end
217
+
218
+ end
219
+ end
220
+
221
+ # @private
222
+ AnsiEscapes = Cucumber::Gherkin::Formatter::AnsiEscapes
223
+ end
224
+ end
225
+ end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
- require 'cucumber/core_ext/instance_exec'
3
- require 'cucumber/rb_support/rb_dsl'
4
- require 'cucumber/rb_support/rb_world'
5
- require 'cucumber/rb_support/rb_step_definition'
6
- require 'cucumber/rb_support/rb_hook'
7
- require 'cucumber/rb_support/rb_transform'
8
- require 'cucumber/rb_support/snippet'
2
+ require 'cucumber/cucumber_expressions/parameter_type_registry'
3
+ require 'cucumber/cucumber_expressions/cucumber_expression'
4
+ require 'cucumber/cucumber_expressions/regular_expression'
5
+ require 'cucumber/cucumber_expressions/cucumber_expression_generator'
6
+ require 'cucumber/glue/dsl'
7
+ require 'cucumber/glue/snippet'
8
+ require 'cucumber/glue/hook'
9
+ require 'cucumber/glue/proto_world'
10
+ require 'cucumber/glue/step_definition'
11
+ require 'cucumber/glue/world_factory'
9
12
  require 'cucumber/gherkin/i18n'
10
13
  require 'multi_test'
11
14
  require 'cucumber/step_match'
@@ -13,11 +16,11 @@ require 'cucumber/step_definition_light'
13
16
  require 'cucumber/events/step_definition_registered'
14
17
 
15
18
  module Cucumber
16
- module RbSupport
19
+ module Glue
17
20
  # Raised if a World block returns Nil.
18
21
  class NilWorld < StandardError
19
22
  def initialize
20
- super("World procs should never return nil")
23
+ super('World procs should never return nil')
21
24
  end
22
25
  end
23
26
 
@@ -27,16 +30,16 @@ module Cucumber
27
30
  message = String.new
28
31
  message << "You can only pass a proc to #World once, but it's happening\n"
29
32
  message << "in 2 places:\n\n"
30
- message << RbSupport.backtrace_line(first_proc, 'World') << "\n"
31
- message << RbSupport.backtrace_line(second_proc, 'World') << "\n\n"
32
- message << "Use Ruby modules instead to extend your worlds. See the Cucumber::RbSupport::RbDsl#World RDoc\n"
33
+ message << Glue.backtrace_line(first_proc, 'World') << "\n"
34
+ message << Glue.backtrace_line(second_proc, 'World') << "\n\n"
35
+ message << "Use Ruby modules instead to extend your worlds. See the Cucumber::Glue::Dsl#World RDoc\n"
33
36
  message << "or http://wiki.github.com/cucumber/cucumber/a-whole-new-world.\n\n"
34
37
  super(message)
35
38
  end
36
39
  end
37
40
 
38
- # The Ruby implementation of the programming language API.
39
- class RbLanguage
41
+ # TODO: This class has too many responsibilities, split off
42
+ class RegistryAndMore
40
43
  attr_reader :current_world,
41
44
  :step_definitions
42
45
 
@@ -45,15 +48,17 @@ module Cucumber
45
48
  dialect.given_keywords + dialect.when_keywords + dialect.then_keywords + dialect.and_keywords + dialect.but_keywords
46
49
  end
47
50
  Cucumber::Gherkin::I18n.code_keywords_for(all_keywords.flatten.uniq.sort).each do |adverb|
48
- RbDsl.alias_adverb(adverb.strip)
51
+ Glue::Dsl.alias_adverb(adverb.strip)
49
52
  end
50
53
 
51
54
  def initialize(runtime, configuration)
52
55
  @runtime, @configuration = runtime, configuration
53
56
  @step_definitions = []
54
- RbDsl.rb_language = self
57
+ Glue::Dsl.rb_language = self
55
58
  @world_proc = @world_modules = nil
56
- @configuration.register_snippet_generator(Snippet::Generator.new)
59
+ @parameter_type_registry = CucumberExpressions::ParameterTypeRegistry.new
60
+ cucumber_expression_generator = CucumberExpressions::CucumberExpressionGenerator.new(@parameter_type_registry)
61
+ @configuration.register_snippet_generator(Snippet::Generator.new(cucumber_expression_generator))
57
62
  end
58
63
 
59
64
  def step_matches(name_to_match)
@@ -65,22 +70,16 @@ module Cucumber
65
70
  }
66
71
  end
67
72
 
68
- def begin_rb_scenario(scenario)
69
- create_world
70
- extend_world
71
- connect_world(scenario)
72
- end
73
-
74
73
  def register_rb_hook(phase, tag_expressions, proc)
75
- add_hook(phase, RbHook.new(self, tag_expressions, proc))
74
+ add_hook(phase, Hook.new(self, tag_expressions, proc))
76
75
  end
77
76
 
78
- def register_rb_transform(regexp, proc)
79
- add_transform(RbTransform.new(self, regexp, proc))
77
+ def define_parameter_type(parameter_type)
78
+ @parameter_type_registry.define_parameter_type(parameter_type)
80
79
  end
81
80
 
82
- def register_rb_step_definition(regexp, proc_or_sym, options)
83
- step_definition = RbStepDefinition.new(self, regexp, proc_or_sym, options)
81
+ def register_rb_step_definition(string_or_regexp, proc_or_sym, options)
82
+ step_definition = StepDefinition.new(self, string_or_regexp, proc_or_sym, options)
84
83
  @step_definitions << step_definition
85
84
  @configuration.notify :step_definition_registered, step_definition
86
85
  step_definition
@@ -103,12 +102,16 @@ module Cucumber
103
102
  end
104
103
 
105
104
  def load_code_file(code_file)
106
- return unless File.extname(code_file) == ".rb"
107
- load File.expand_path(code_file) # This will cause self.add_step_definition, self.add_hook, and self.add_transform to be called from RbDsl
105
+ return unless File.extname(code_file) == '.rb'
106
+ load File.expand_path(code_file) # This will cause self.add_step_definition, self.add_hook, and self.define_parameter_type to be called from Glue::Dsl
108
107
  end
109
108
 
110
- def begin_scenario(scenario)
111
- begin_rb_scenario(scenario)
109
+ def begin_scenario(test_case)
110
+ @current_world = WorldFactory.new(@world_proc).create_world
111
+ @current_world.extend(ProtoWorld.for(@runtime, test_case.language))
112
+ MultiTest.extend_with_best_assertion_library(@current_world)
113
+ @current_world.add_modules!(@world_modules || [],
114
+ @namespaced_world_modules || {})
112
115
  end
113
116
 
114
117
  def end_scenario
@@ -121,13 +124,6 @@ module Cucumber
121
124
  end
122
125
  end
123
126
 
124
- def execute_transforms(args)
125
- args.map do |arg|
126
- matching_transform = transforms.detect {|transform| transform.match(arg) }
127
- matching_transform ? matching_transform.invoke(arg) : arg
128
- end
129
- end
130
-
131
127
  def add_hook(phase, hook)
132
128
  hooks[phase.to_sym] << hook
133
129
  hook
@@ -137,11 +133,6 @@ module Cucumber
137
133
  @hooks = nil
138
134
  end
139
135
 
140
- def add_transform(transform)
141
- transforms.unshift transform
142
- transform
143
- end
144
-
145
136
  def hooks_for(phase, scenario) #:nodoc:
146
137
  hooks[phase.to_sym].select{|hook| scenario.accept_hook?(hook)}
147
138
  end
@@ -158,6 +149,12 @@ module Cucumber
158
149
  invoked_step_definition_hash[StepDefinitionLight.new(regexp_source, file_colon_line)] = nil
159
150
  end
160
151
 
152
+ def create_expression(string_or_regexp)
153
+ return CucumberExpressions::CucumberExpression.new(string_or_regexp, @parameter_type_registry) if string_or_regexp.is_a?(String)
154
+ return CucumberExpressions::RegularExpression.new(string_or_regexp, @parameter_type_registry) if string_or_regexp.is_a?(Regexp)
155
+ raise ArgumentError.new('Expression must be a String or Regexp')
156
+ end
157
+
161
158
  private
162
159
 
163
160
  def available_step_definition_hash
@@ -172,56 +169,18 @@ module Cucumber
172
169
  @hooks ||= Hash.new{|h,k| h[k] = []}
173
170
  end
174
171
 
175
- def transforms
176
- @transforms ||= []
177
- end
178
-
179
- def create_world
180
- if(@world_proc)
181
- @current_world = @world_proc.call
182
- check_nil(@current_world, @world_proc)
183
- else
184
- @current_world = Object.new
185
- end
186
- end
187
-
188
- def extend_world
189
- @current_world.extend(RbWorld)
190
- MultiTest.extend_with_best_assertion_library(@current_world)
191
-
192
- @current_world.add_modules!(@world_modules || [],
193
- @namespaced_world_modules || {})
194
- end
195
-
196
- def connect_world(scenario)
197
- @current_world.__cucumber_runtime = @runtime
198
- @current_world.__natural_language = scenario.language
199
- end
200
-
201
- def check_nil(o, proc)
202
- if o.nil?
203
- begin
204
- raise NilWorld.new
205
- rescue NilWorld => e
206
- e.backtrace.clear
207
- e.backtrace.push(RbSupport.backtrace_line(proc, "World"))
208
- raise e
209
- end
210
- else
211
- o
212
- end
213
- end
214
-
215
172
  def self.cli_snippet_type_options
173
+ registry = CucumberExpressions::ParameterTypeRegistry.new
174
+ cucumber_expression_generator = CucumberExpressions::CucumberExpressionGenerator.new(registry)
216
175
  Snippet::SNIPPET_TYPES.keys.sort_by(&:to_s).map do |type|
217
- Snippet::SNIPPET_TYPES[type].cli_option_string(type)
176
+ Snippet::SNIPPET_TYPES[type].cli_option_string(type, cucumber_expression_generator)
218
177
  end
219
178
  end
220
179
  end
221
180
 
222
181
  def self.backtrace_line(proc, name)
223
182
  location = Cucumber::Core::Ast::Location.from_source_location(*proc.source_location)
224
- "#{location.to_s}:in `#{name}'"
183
+ "#{location}:in `#{name}'"
225
184
  end
226
185
  end
227
186
  end