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,207 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+ require 'cucumber/glue/registry_and_more'
4
+
5
+ module Cucumber
6
+ module Glue
7
+ describe StepDefinition do
8
+ let(:user_interface) { double('user interface') }
9
+ let(:support_code) { Cucumber::Runtime::SupportCode.new(user_interface) }
10
+ let(:registry) { support_code.registry }
11
+ let(:scenario) { double('scenario', iso_code: 'en').as_null_object }
12
+ let(:dsl) do
13
+ registry
14
+ Object.new.extend(Cucumber::Glue::Dsl)
15
+ end
16
+
17
+ before do
18
+ registry.begin_scenario(scenario)
19
+ $inside = nil
20
+ end
21
+
22
+ def run_step(text)
23
+ step_match(text).invoke(MultilineArgument::None.new)
24
+ end
25
+
26
+ def step_match(text)
27
+ StepMatchSearch.new(registry.method(:step_matches), Configuration.default).call(text).first
28
+ end
29
+
30
+ it 'allows calling of other steps' do
31
+ dsl.Given(/Outside/) do
32
+ step 'Inside'
33
+ end
34
+ dsl.Given(/Inside/) do
35
+ $inside = true
36
+ end
37
+
38
+ run_step 'Outside'
39
+
40
+ expect($inside).to be true
41
+ end
42
+
43
+ it 'allows calling of other steps with inline arg' do
44
+ dsl.Given(/Outside/) do
45
+ step 'Inside', table([['inside']])
46
+ end
47
+ dsl.Given(/Inside/) do |t|
48
+ $inside = t.raw[0][0]
49
+ end
50
+
51
+ run_step 'Outside'
52
+
53
+ expect($inside).to eq 'inside'
54
+ end
55
+
56
+ context 'mapping to world methods' do
57
+ it 'calls a method on the world when specified with a symbol' do
58
+ expect(registry.current_world).to receive(:with_symbol)
59
+
60
+ dsl.Given(/With symbol/, :with_symbol)
61
+
62
+ run_step 'With symbol'
63
+ end
64
+
65
+ it 'calls a method on a specified object' do
66
+ target = double('target')
67
+
68
+ allow(registry.current_world).to receive(:target) { target }
69
+
70
+ dsl.Given(/With symbol on block/, :with_symbol, :on => lambda { target })
71
+
72
+ expect(target).to receive(:with_symbol)
73
+
74
+ run_step 'With symbol on block'
75
+ end
76
+
77
+ it 'calls a method on a specified world attribute' do
78
+ target = double('target')
79
+
80
+ allow(registry.current_world).to receive(:target) { target }
81
+
82
+ dsl.Given(/With symbol on symbol/, :with_symbol, :on => :target)
83
+
84
+ expect(target).to receive(:with_symbol)
85
+
86
+ run_step 'With symbol on symbol'
87
+ end
88
+
89
+ it 'has the correct location' do
90
+ dsl.Given(/With symbol/, :with_symbol)
91
+ expect(step_match('With symbol').file_colon_line).to eq "spec/cucumber/glue/step_definition_spec.rb:#{__LINE__-1}"
92
+ end
93
+ end
94
+
95
+ it 'raises UndefinedDynamicStep when inside step is not defined' do
96
+ dsl.Given(/Outside/) do
97
+ step 'Inside'
98
+ end
99
+
100
+ expect(-> {
101
+ run_step 'Outside'
102
+ }).to raise_error(Cucumber::UndefinedDynamicStep)
103
+ end
104
+
105
+ it 'raises UndefinedDynamicStep when an undefined step is parsed dynamically' do
106
+ dsl.Given(/Outside/) do
107
+ steps %{
108
+ Given Inside
109
+ }
110
+ end
111
+
112
+ expect(-> {
113
+ run_step 'Outside'
114
+ }).to raise_error(Cucumber::UndefinedDynamicStep)
115
+ end
116
+
117
+ it 'raises UndefinedDynamicStep when an undefined step with doc string is parsed dynamically' do
118
+ dsl.Given(/Outside/) do
119
+ steps %{
120
+ Given Inside
121
+ """
122
+ abc
123
+ """
124
+ }
125
+ end
126
+
127
+ expect(-> {
128
+ run_step 'Outside'
129
+ }).to raise_error(Cucumber::UndefinedDynamicStep)
130
+ end
131
+
132
+ it 'raises UndefinedDynamicStep when an undefined step with data table is parsed dynamically' do
133
+ dsl.Given(/Outside/) do
134
+ steps %{
135
+ Given Inside
136
+ | a |
137
+ | 1 |
138
+ }
139
+ end
140
+
141
+ expect(-> {
142
+ run_step 'Outside'
143
+ }).to raise_error(Cucumber::UndefinedDynamicStep)
144
+ end
145
+
146
+ it 'allows forced pending' do
147
+ dsl.Given(/Outside/) do
148
+ pending('Do me!')
149
+ end
150
+
151
+ expect(-> {
152
+ run_step 'Outside'
153
+ }).to raise_error(Cucumber::Pending, 'Do me!')
154
+ end
155
+
156
+ it 'raises ArityMismatchError when the number of capture groups differs from the number of step arguments' do
157
+ dsl.Given(/No group: \w+/) do |arg|
158
+ end
159
+
160
+ expect(-> {
161
+ run_step 'No group: arg'
162
+ }).to raise_error(Cucumber::Glue::ArityMismatchError)
163
+ end
164
+
165
+ it 'does not modify the step_match arg when arg is modified in a step' do
166
+ dsl.Given(/My car is (.*)/) do |colour|
167
+ colour << 'xxx'
168
+ end
169
+
170
+ step_name = 'My car is white'
171
+ step_args = step_match(step_name).args
172
+
173
+ expect(-> {
174
+ run_step step_name
175
+ }).not_to change{ step_args.first }
176
+ end
177
+
178
+ it 'allows puts' do
179
+ expect(user_interface).to receive(:puts).with('wasup')
180
+ dsl.Given(/Loud/) do
181
+ puts 'wasup'
182
+ end
183
+ run_step 'Loud'
184
+ end
185
+
186
+ it 'recognizes $arg style captures' do
187
+ arg_value = 'up'
188
+ dsl.Given 'capture this: {word}' do |arg|
189
+ expect(arg).to eq arg_value
190
+ end
191
+ run_step 'capture this: up'
192
+ end
193
+
194
+ it 'has a JSON representation of the signature' do
195
+ expect(StepDefinition.new(registry, /I CAN HAZ (\d+) CUKES/i, lambda{}, {}).to_hash).to eq({
196
+ source: {
197
+ type: 'regular expression',
198
+ expression: 'I CAN HAZ (\\d+) CUKES'
199
+ },
200
+ regexp: {
201
+ source: 'I CAN HAZ (\\d+) CUKES', flags: 'i'
202
+ }
203
+ })
204
+ end
205
+ end
206
+ end
207
+ end
@@ -2,15 +2,15 @@
2
2
  require 'cucumber/hooks'
3
3
  module Cucumber::Hooks
4
4
  shared_examples_for 'a source node' do
5
- it "responds to name" do
5
+ it 'responds to name' do
6
6
  expect( subject.name ).to be_a(String)
7
7
  end
8
8
 
9
- it "responds to location" do
9
+ it 'responds to location' do
10
10
  expect( subject.location ).to eq(location)
11
11
  end
12
12
 
13
- it "responds to match_locations?" do
13
+ it 'responds to match_locations?' do
14
14
  expect( subject.match_locations? [location] ).to be_truthy
15
15
  expect( subject.match_locations? [] ).to be_falsey
16
16
  end
@@ -13,30 +13,30 @@ module Cucumber
13
13
  ])
14
14
  end
15
15
 
16
- it "should have rows" do
16
+ it 'should have rows' do
17
17
  expect( @table.cells_rows[0].map{|cell| cell.value} ).to eq %w{one four seven}
18
18
  end
19
19
 
20
- it "should have columns" do
20
+ it 'should have columns' do
21
21
  expect( @table.columns[1].map{|cell| cell.value} ).to eq %w{four 55555}
22
22
  end
23
23
 
24
- it "should have same cell objects in rows and columns" do
24
+ it 'should have same cell objects in rows and columns' do
25
25
  # 666666
26
26
  expect( @table.cells_rows[1][2] ).to equal(@table.columns[2][1])
27
27
  end
28
28
 
29
- it "should be convertible to an array of hashes" do
29
+ it 'should be convertible to an array of hashes' do
30
30
  expect( @table.hashes ).to eq [
31
31
  {'one' => '4444', 'four' => '55555', 'seven' => '666666'}
32
32
  ]
33
33
  end
34
34
 
35
- it "should accept symbols as keys for the hashes" do
35
+ it 'should accept symbols as keys for the hashes' do
36
36
  expect( @table.hashes.first[:one] ).to eq '4444'
37
37
  end
38
38
 
39
- it "should return the row values in order" do
39
+ it 'should return the row values in order' do
40
40
  expect( @table.rows.first ).to eq %w{4444 55555 666666}
41
41
  end
42
42
 
@@ -56,12 +56,12 @@ module Cucumber
56
56
  end
57
57
 
58
58
  describe '#map_column!' do
59
- it "should allow mapping columns" do
59
+ it 'should allow mapping columns' do
60
60
  @table.map_column!('one') { |v| v.to_i }
61
61
  expect( @table.hashes.first['one'] ).to eq 4444
62
62
  end
63
63
 
64
- it "applies the block once to each value" do
64
+ it 'applies the block once to each value' do
65
65
  headers = ['header']
66
66
  rows = ['value']
67
67
  table = DataTable.from [headers, rows]
@@ -71,43 +71,43 @@ module Cucumber
71
71
  expect( count ).to eq rows.size
72
72
  end
73
73
 
74
- it "should allow mapping columns and take a symbol as the column name" do
74
+ it 'should allow mapping columns and take a symbol as the column name' do
75
75
  @table.map_column!(:one) { |v| v.to_i }
76
76
  expect( @table.hashes.first['one'] ).to eq 4444
77
77
  end
78
78
 
79
- it "should allow mapping columns and modify the rows as well" do
79
+ it 'should allow mapping columns and modify the rows as well' do
80
80
  @table.map_column!(:one) { |v| v.to_i }
81
81
  expect( @table.rows.first ).to include(4444)
82
82
  expect( @table.rows.first ).to_not include('4444')
83
83
  end
84
84
 
85
- it "should pass silently if a mapped column does not exist in non-strict mode" do
85
+ it 'should pass silently if a mapped column does not exist in non-strict mode' do
86
86
  expect {
87
87
  @table.map_column!('two', false) { |v| v.to_i }
88
88
  @table.hashes
89
89
  }.not_to raise_error
90
90
  end
91
91
 
92
- it "should fail if a mapped column does not exist in strict mode" do
92
+ it 'should fail if a mapped column does not exist in strict mode' do
93
93
  expect {
94
94
  @table.map_column!('two', true) { |v| v.to_i }
95
95
  @table.hashes
96
96
  }.to raise_error('The column named "two" does not exist')
97
97
  end
98
98
 
99
- it "should return the table" do
99
+ it 'should return the table' do
100
100
  expect( (@table.map_column!(:one) { |v| v.to_i }) ).to eq @table
101
101
  end
102
102
  end
103
103
 
104
104
  describe '#map_column' do
105
- it "should allow mapping columns" do
105
+ it 'should allow mapping columns' do
106
106
  new_table = @table.map_column('one') { |v| v.to_i }
107
107
  expect( new_table.hashes.first['one'] ).to eq 4444
108
108
  end
109
109
 
110
- it "applies the block once to each value" do
110
+ it 'applies the block once to each value' do
111
111
  headers = ['header']
112
112
  rows = ['value']
113
113
  table = DataTable.from [headers, rows]
@@ -117,37 +117,37 @@ module Cucumber
117
117
  expect( count ).to eq rows.size
118
118
  end
119
119
 
120
- it "should allow mapping columns and take a symbol as the column name" do
120
+ it 'should allow mapping columns and take a symbol as the column name' do
121
121
  new_table = @table.map_column(:one) { |v| v.to_i }
122
122
  expect( new_table.hashes.first['one'] ).to eq 4444
123
123
  end
124
124
 
125
- it "should allow mapping columns and modify the rows as well" do
125
+ it 'should allow mapping columns and modify the rows as well' do
126
126
  new_table = @table.map_column(:one) { |v| v.to_i }
127
127
  expect( new_table.rows.first ).to include(4444)
128
128
  expect( new_table.rows.first ).to_not include('4444')
129
129
  end
130
130
 
131
- it "should pass silently if a mapped column does not exist in non-strict mode" do
131
+ it 'should pass silently if a mapped column does not exist in non-strict mode' do
132
132
  expect {
133
133
  new_table = @table.map_column('two', false) { |v| v.to_i }
134
134
  new_table.hashes
135
135
  }.not_to raise_error
136
136
  end
137
137
 
138
- it "should fail if a mapped column does not exist in strict mode" do
138
+ it 'should fail if a mapped column does not exist in strict mode' do
139
139
  expect {
140
140
  new_table = @table.map_column('two', true) { |v| v.to_i }
141
141
  new_table.hashes
142
142
  }.to raise_error('The column named "two" does not exist')
143
143
  end
144
144
 
145
- it "should return a new table" do
145
+ it 'should return a new table' do
146
146
  expect( (@table.map_column(:one) { |v| v.to_i }) ).to_not eq @table
147
147
  end
148
148
  end
149
149
 
150
- describe "#match" do
150
+ describe '#match' do
151
151
  before(:each) do
152
152
  @table = DataTable.from([
153
153
  %w{one four seven},
@@ -155,18 +155,18 @@ module Cucumber
155
155
  ])
156
156
  end
157
157
 
158
- it "returns nil if headers do not match" do
158
+ it 'returns nil if headers do not match' do
159
159
  expect( @table.match('does,not,match') ).to be_nil
160
160
  end
161
- it "requires a table: prefix on match" do
161
+ it 'requires a table: prefix on match' do
162
162
  expect( @table.match('table:one,four,seven') ).to_not be_nil
163
163
  end
164
- it "does not match if no table: prefix on match" do
164
+ it 'does not match if no table: prefix on match' do
165
165
  expect( @table.match('one,four,seven') ).to be_nil
166
166
  end
167
167
  end
168
168
 
169
- describe "#transpose" do
169
+ describe '#transpose' do
170
170
  before(:each) do
171
171
  @table = DataTable.from([
172
172
  %w{one 1111},
@@ -174,14 +174,14 @@ module Cucumber
174
174
  ])
175
175
  end
176
176
 
177
- it "should be convertible in to an array where each row is a hash" do
177
+ it 'should be convertible in to an array where each row is a hash' do
178
178
  expect( @table.transpose.hashes[0] ).to eq('one' => '1111', 'two' => '22222')
179
179
  end
180
180
  end
181
181
 
182
- describe "#rows_hash" do
182
+ describe '#rows_hash' do
183
183
 
184
- it "should return a hash of the rows" do
184
+ it 'should return a hash of the rows' do
185
185
  table = DataTable.from([
186
186
  %w{one 1111},
187
187
  %w{two 22222}
@@ -199,7 +199,7 @@ module Cucumber
199
199
  }.to raise_error('The table must have exactly 2 columns')
200
200
  end
201
201
 
202
- it "should support header and column mapping" do
202
+ it 'should support header and column mapping' do
203
203
  table = DataTable.from([
204
204
  %w{one 1111},
205
205
  %w{two 22222}
@@ -218,30 +218,30 @@ module Cucumber
218
218
  ])
219
219
  end
220
220
 
221
- it "renames the columns to the specified values in the provided hash" do
221
+ it 'renames the columns to the specified values in the provided hash' do
222
222
  @table.map_headers!('one' => :three)
223
223
  expect( @table.hashes.first[:three] ).to eq '4444'
224
224
  end
225
225
 
226
- it "allows renaming columns using regexp" do
226
+ it 'allows renaming columns using regexp' do
227
227
  @table.map_headers!(/one|uno/ => :three)
228
228
  expect( @table.hashes.first[:three] ).to eq '4444'
229
229
  end
230
230
 
231
- it "copies column mappings" do
231
+ it 'copies column mappings' do
232
232
  @table.map_column!('one') { |v| v.to_i }
233
233
  @table.map_headers!('one' => 'three')
234
234
  expect( @table.hashes.first['three'] ).to eq 4444
235
235
  end
236
236
 
237
- it "takes a block and operates on all the headers with it" do
237
+ it 'takes a block and operates on all the headers with it' do
238
238
  table.map_headers! do |header|
239
239
  header.downcase
240
240
  end
241
241
  expect( table.hashes.first.keys ).to match %w[hello world]
242
242
  end
243
243
 
244
- it "treats the mappings in the provided hash as overrides when used with a block" do
244
+ it 'treats the mappings in the provided hash as overrides when used with a block' do
245
245
  table.map_headers!('WORLD' => 'foo') do |header|
246
246
  header.downcase
247
247
  end
@@ -258,23 +258,23 @@ module Cucumber
258
258
  ])
259
259
  end
260
260
 
261
- it "renames the columns to the specified values in the provided hash" do
261
+ it 'renames the columns to the specified values in the provided hash' do
262
262
  table2 = @table.map_headers('one' => :three)
263
263
  expect( table2.hashes.first[:three] ).to eq '4444'
264
264
  end
265
265
 
266
- it "allows renaming columns using regexp" do
266
+ it 'allows renaming columns using regexp' do
267
267
  table2 = @table.map_headers(/one|uno/ => :three)
268
268
  expect( table2.hashes.first[:three] ).to eq '4444'
269
269
  end
270
270
 
271
- it "copies column mappings" do
271
+ it 'copies column mappings' do
272
272
  @table.map_column!('one') { |v| v.to_i }
273
273
  table2 = @table.map_headers('one' => 'three')
274
274
  expect( table2.hashes.first['three'] ).to eq 4444
275
275
  end
276
276
 
277
- it "takes a block and operates on all the headers with it" do
277
+ it 'takes a block and operates on all the headers with it' do
278
278
  table2 = table.map_headers do |header|
279
279
  header.downcase
280
280
  end
@@ -282,7 +282,7 @@ module Cucumber
282
282
  expect( table2.hashes.first.keys ).to match %w[hello world]
283
283
  end
284
284
 
285
- it "treats the mappings in the provided hash as overrides when used with a block" do
285
+ it 'treats the mappings in the provided hash as overrides when used with a block' do
286
286
  table2 = table.map_headers('WORLD' => 'foo') do |header|
287
287
  header.downcase
288
288
  end
@@ -291,8 +291,8 @@ module Cucumber
291
291
  end
292
292
  end
293
293
 
294
- describe "diff!" do
295
- it "should detect a complex diff" do
294
+ describe 'diff!' do
295
+ it 'should detect a complex diff' do
296
296
  t1 = DataTable.from(%{
297
297
  | 1 | 22 | 333 | 4444 |
298
298
  | 55555 | 666666 | 7777777 | 88888888 |
@@ -307,18 +307,19 @@ module Cucumber
307
307
  | dddd | 4000 | 300 |
308
308
  | e | 50000 | 4000 |
309
309
  })
310
- expect { t1.diff!(t2) }.to raise_error
311
- expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
312
- | 1 | (-) 22 | (-) 333 | 4444 | (+) a |
313
- | 55555 | (-) 666666 | (-) 7777777 | 88888888 | (+) bb |
314
- | (-) 999999999 | (-) 0000000000 | (-) 01010101010 | (-) 121212121212 | (+) |
315
- | (+) 999999999 | (+) | (+) | (+) xxxxxxxx | (+) ccc |
316
- | (+) 300 | (+) | (+) | (+) 4000 | (+) dddd |
317
- | 4000 | (-) ABC | (-) DEF | 50000 | (+) e |
318
- }
310
+ expect { t1.diff!(t2) }.to raise_error(DataTable::Different) do |error|
311
+ expect(error.table.to_s(indent: 14, color: false)).to eq %{
312
+ | 1 | (-) 22 | (-) 333 | 4444 | (+) a |
313
+ | 55555 | (-) 666666 | (-) 7777777 | 88888888 | (+) bb |
314
+ | (-) 999999999 | (-) 0000000000 | (-) 01010101010 | (-) 121212121212 | (+) |
315
+ | (+) 999999999 | (+) | (+) | (+) xxxxxxxx | (+) ccc |
316
+ | (+) 300 | (+) | (+) | (+) 4000 | (+) dddd |
317
+ | 4000 | (-) ABC | (-) DEF | 50000 | (+) e |
318
+ }
319
+ end
319
320
  end
320
321
 
321
- it "should not change table when diffed with identical" do
322
+ it 'should not change table when diffed with identical' do
322
323
  t = DataTable.from(%{
323
324
  |a|b|c|
324
325
  |d|e|f|
@@ -332,8 +333,48 @@ module Cucumber
332
333
  }
333
334
  end
334
335
 
335
- context "in case of duplicate header values" do
336
- it "raises no error for two identical tables" do
336
+ context 'with empty tables' do
337
+ it 'should allow diffing empty tables' do
338
+ t1 = DataTable.from([[]])
339
+ t2 = DataTable.from([[]])
340
+ expect{ t1.diff!(t2) }.not_to raise_error
341
+ end
342
+
343
+ it 'should be able to diff when the right table is empty' do
344
+ t1 = DataTable.from(%{
345
+ |a|b|c|
346
+ |d|e|f|
347
+ |g|h|i|
348
+ })
349
+ t2 = DataTable.from([[]])
350
+ expect { t1.diff!(t2) }.to raise_error(DataTable::Different) do |error|
351
+ expect(error.table.to_s(indent: 16, color: false)).to eq %{
352
+ | (-) a | (-) b | (-) c |
353
+ | (-) d | (-) e | (-) f |
354
+ | (-) g | (-) h | (-) i |
355
+ }
356
+ end
357
+ end
358
+
359
+ it 'should be able to diff when the left table is empty' do
360
+ t1 = DataTable.from([[]])
361
+ t2 = DataTable.from(%{
362
+ |a|b|c|
363
+ |d|e|f|
364
+ |g|h|i|
365
+ })
366
+ expect { t1.diff!(t2) }.to raise_error(DataTable::Different) do |error|
367
+ expect(error.table.to_s(indent: 16, color: false)).to eq %{
368
+ | (+) a | (+) b | (+) c |
369
+ | (+) d | (+) e | (+) f |
370
+ | (+) g | (+) h | (+) i |
371
+ }
372
+ end
373
+ end
374
+ end
375
+
376
+ context 'in case of duplicate header values' do
377
+ it 'raises no error for two identical tables' do
337
378
  t = DataTable.from(%{
338
379
  |a|a|c|
339
380
  |d|e|f|
@@ -347,7 +388,7 @@ module Cucumber
347
388
  }
348
389
  end
349
390
 
350
- it "detects a diff in one cell" do
391
+ it 'detects a diff in one cell' do
351
392
  t1 = DataTable.from(%{
352
393
  |a|a|c|
353
394
  |d|e|f|
@@ -358,16 +399,17 @@ module Cucumber
358
399
  |d|oops|f|
359
400
  |g|h|i|
360
401
  })
361
- expect{ t1.diff!(t2) }.to raise_error
362
- expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
363
- | a | a | c |
364
- | (-) d | (-) e | (-) f |
365
- | (+) d | (+) oops | (+) f |
366
- | g | h | i |
367
- }
402
+ expect{ t1.diff!(t2) }.to raise_error(DataTable::Different) do |error|
403
+ expect(error.table.to_s(indent: 16, color: false)).to eq %{
404
+ | a | a | c |
405
+ | (-) d | (-) e | (-) f |
406
+ | (+) d | (+) oops | (+) f |
407
+ | g | h | i |
408
+ }
409
+ end
368
410
  end
369
411
 
370
- it "detects missing columns" do
412
+ it 'detects missing columns' do
371
413
  t1 = DataTable.from(%{
372
414
  |a|a|b|c|
373
415
  |d|d|e|f|
@@ -378,15 +420,16 @@ module Cucumber
378
420
  |d|e|f|
379
421
  |g|h|i|
380
422
  })
381
- expect{ t1.diff!(t2) }.to raise_error
382
- expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
383
- | a | (-) a | b | c |
384
- | d | (-) d | e | f |
385
- | g | (-) g | h | i |
386
- }
423
+ expect{ t1.diff!(t2) }.to raise_error(DataTable::Different) do |error|
424
+ expect(error.table.to_s(indent: 16, color: false)).to eq %{
425
+ | a | (-) a | b | c |
426
+ | d | (-) d | e | f |
427
+ | g | (-) g | h | i |
428
+ }
429
+ end
387
430
  end
388
431
 
389
- it "detects surplus columns" do
432
+ it 'detects surplus columns' do
390
433
  t1 = DataTable.from(%{
391
434
  |a|b|c|
392
435
  |d|e|f|
@@ -397,42 +440,43 @@ module Cucumber
397
440
  |d|e|d|f|
398
441
  |g|h|g|i|
399
442
  })
400
- expect{ t1.diff!(t2, :surplus_col => true) }.to raise_error
401
- expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
402
- | a | b | c | (+) a |
403
- | d | e | f | (+) d |
404
- | g | h | i | (+) g |
405
- }
443
+ expect{ t1.diff!(t2, :surplus_col => true) }.to raise_error(DataTable::Different) do |error|
444
+ expect(error.table.to_s(indent: 16, color: false)).to eq %{
445
+ | a | b | c | (+) a |
446
+ | d | e | f | (+) d |
447
+ | g | h | i | (+) g |
448
+ }
449
+ end
406
450
  end
407
451
  end
408
452
 
409
- it "should inspect missing and surplus cells" do
453
+ it 'should inspect missing and surplus cells' do
410
454
  t1 = DataTable.from([
411
- ['name', 'male', 'lastname', 'swedish'],
412
- ['aslak', 'true', 'hellesøy', 'false']
455
+ %w(name male lastname swedish),
456
+ %w(aslak true hellesøy false)
413
457
  ])
414
458
  t2 = DataTable.from([
415
- ['name', 'male', 'lastname', 'swedish'],
416
- ['aslak', true, 'hellesøy', false]
459
+ %w(name male lastname swedish),
460
+ ['aslak', true, 'hellesøy', false]
417
461
  ])
418
- expect { t1.diff!(t2) }.to raise_error
419
-
420
- expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
421
- | name | male | lastname | swedish |
422
- | (-) aslak | (-) (i) "true" | (-) hellesøy | (-) (i) "false" |
423
- | (+) aslak | (+) (i) true | (+) hellesøy | (+) (i) false |
424
- }
462
+ expect { t1.diff!(t2) }.to raise_error(DataTable::Different) do |error|
463
+ expect(error.table.to_s(indent: 14, color: false)).to eq %{
464
+ | name | male | lastname | swedish |
465
+ | (-) aslak | (-) (i) "true" | (-) hellesøy | (-) (i) "false" |
466
+ | (+) aslak | (+) (i) true | (+) hellesøy | (+) (i) false |
467
+ }
468
+ end
425
469
  end
426
470
 
427
- it "should allow column mapping of target before diffing" do
471
+ it 'should allow column mapping of target before diffing' do
428
472
  t1 = DataTable.from([
429
- ['name', 'male'],
430
- ['aslak', 'true']
473
+ %w(name male),
474
+ %w(aslak true)
431
475
  ])
432
476
  t1.map_column!('male') { |m| m == 'true' }
433
477
  t2 = DataTable.from([
434
- ['name', 'male'],
435
- ['aslak', true]
478
+ %w(name male),
479
+ ['aslak', true]
436
480
  ])
437
481
  t1.diff!(t2)
438
482
  expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
@@ -441,17 +485,17 @@ module Cucumber
441
485
  }
442
486
  end
443
487
 
444
- it "should allow column mapping of argument before diffing" do
488
+ it 'should allow column mapping of argument before diffing' do
445
489
  t1 = DataTable.from([
446
- ['name', 'male'],
447
- ['aslak', true]
490
+ %w(name male),
491
+ ['aslak', true]
448
492
  ])
449
493
  t1.map_column!('male') {
450
494
  'true'
451
495
  }
452
496
  t2 = DataTable.from([
453
- ['name', 'male'],
454
- ['aslak', 'true']
497
+ %w(name male),
498
+ %w(aslak true)
455
499
  ])
456
500
  t2.diff!(t1)
457
501
  expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
@@ -460,16 +504,16 @@ module Cucumber
460
504
  }
461
505
  end
462
506
 
463
- it "should allow header mapping before diffing" do
507
+ it 'should allow header mapping before diffing' do
464
508
  t1 = DataTable.from([
465
- ['Name', 'Male'],
466
- ['aslak', 'true']
509
+ %w(Name Male),
510
+ %w(aslak true)
467
511
  ])
468
512
  t1.map_headers!('Name' => 'name', 'Male' => 'male')
469
513
  t1.map_column!('male') { |m| m == 'true' }
470
514
  t2 = DataTable.from([
471
- ['name', 'male'],
472
- ['aslak', true]
515
+ %w(name male),
516
+ ['aslak', true]
473
517
  ])
474
518
  t1.diff!(t2)
475
519
  expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
@@ -478,27 +522,28 @@ module Cucumber
478
522
  }
479
523
  end
480
524
 
481
- it "should detect seemingly identical tables as different" do
525
+ it 'should detect seemingly identical tables as different' do
482
526
  t1 = DataTable.from([
483
- ['X', 'Y'],
484
- ['2', '1']
527
+ %w(X Y),
528
+ %w(2 1)
485
529
  ])
486
530
  t2 = DataTable.from([
487
- ['X', 'Y'],
488
- [2, 1]
531
+ %w(X Y),
532
+ [2, 1]
489
533
  ])
490
- expect { t1.diff!(t2) }.to raise_error
491
- expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
492
- | X | Y |
493
- | (-) (i) "2" | (-) (i) "1" |
494
- | (+) (i) 2 | (+) (i) 1 |
495
- }
534
+ expect { t1.diff!(t2) }.to raise_error(DataTable::Different) do |error|
535
+ expect(error.table.to_s(indent: 14, color: false)).to eq %{
536
+ | X | Y |
537
+ | (-) (i) "2" | (-) (i) "1" |
538
+ | (+) (i) 2 | (+) (i) 1 |
539
+ }
540
+ end
496
541
  end
497
542
 
498
- it "should not allow mappings that match more than 1 column" do
543
+ it 'should not allow mappings that match more than 1 column' do
499
544
  t1 = DataTable.from([
500
- ['Cuke', 'Duke'],
501
- ['Foo', 'Bar']
545
+ %w(Cuke Duke),
546
+ %w(Foo Bar)
502
547
  ])
503
548
  expect do
504
549
  t1.map_headers!(/uk/ => 'u')
@@ -506,7 +551,7 @@ module Cucumber
506
551
  end.to raise_error(%{2 headers matched /uk/: ["Cuke", "Duke"]})
507
552
  end
508
553
 
509
- describe "raising" do
554
+ describe 'raising' do
510
555
  before do
511
556
  @t = DataTable.from(%{
512
557
  | a | b |
@@ -515,25 +560,25 @@ module Cucumber
515
560
  expect( @t ).not_to eq nil
516
561
  end
517
562
 
518
- it "should raise on missing rows" do
563
+ it 'should raise on missing rows' do
519
564
  t = DataTable.from(%{
520
565
  | a | b |
521
566
  })
522
- expect( lambda { @t.dup.diff!(t) } ).to raise_error
567
+ expect { @t.dup.diff!(t) }.to raise_error(DataTable::Different)
523
568
  expect { @t.dup.diff!(t, :missing_row => false) }.not_to raise_error
524
569
  end
525
570
 
526
- it "should not raise on surplus rows when surplus is at the end" do
571
+ it 'should not raise on surplus rows when surplus is at the end' do
527
572
  t = DataTable.from(%{
528
573
  | a | b |
529
574
  | c | d |
530
575
  | e | f |
531
576
  })
532
- expect { @t.dup.diff!(t) }.to raise_error
577
+ expect { @t.dup.diff!(t) }.to raise_error(DataTable::Different)
533
578
  expect { @t.dup.diff!(t, :surplus_row => false) }.not_to raise_error
534
579
  end
535
580
 
536
- it "should not raise on surplus rows when surplus is interleaved" do
581
+ it 'should not raise on surplus rows when surplus is interleaved' do
537
582
  t1 = DataTable.from(%{
538
583
  | row_1 | row_2 |
539
584
  | four | 4 |
@@ -546,40 +591,39 @@ module Cucumber
546
591
  | four | 4 |
547
592
  | five | 5 |
548
593
  })
549
- expect { t1.dup.diff!(t2) }.to raise_error
550
-
594
+ expect { t1.dup.diff!(t2) }.to raise_error(DataTable::Different)
551
595
  expect { t1.dup.diff!(t2, :surplus_row => false) }.not_to raise_error
552
596
  end
553
597
 
554
- it "should raise on missing columns" do
598
+ it 'should raise on missing columns' do
555
599
  t = DataTable.from(%{
556
600
  | a |
557
601
  | c |
558
602
  })
559
- expect { @t.dup.diff!(t) }.to raise_error
603
+ expect { @t.dup.diff!(t) }.to raise_error(DataTable::Different)
560
604
  expect { @t.dup.diff!(t, :missing_col => false) }.not_to raise_error
561
605
  end
562
606
 
563
- it "should not raise on surplus columns" do
607
+ it 'should not raise on surplus columns' do
564
608
  t = DataTable.from(%{
565
609
  | a | b | x |
566
610
  | c | d | y |
567
611
  })
568
612
  expect { @t.dup.diff!(t) }.not_to raise_error
569
- expect { @t.dup.diff!(t, :surplus_col => true) }.to raise_error
613
+ expect { @t.dup.diff!(t, :surplus_col => true) }.to raise_error(DataTable::Different)
570
614
  end
571
615
 
572
- it "should not raise on misplaced columns" do
616
+ it 'should not raise on misplaced columns' do
573
617
  t = DataTable.from(%{
574
618
  | b | a |
575
619
  | d | c |
576
620
  })
577
621
  expect { @t.dup.diff!(t) }.not_to raise_error
578
- expect { @t.dup.diff!(t, :misplaced_col => true) }.to raise_error
622
+ expect { @t.dup.diff!(t, :misplaced_col => true) }.to raise_error(DataTable::Different)
579
623
  end
580
624
  end
581
625
 
582
- it "can compare to an Array" do
626
+ it 'can compare to an Array' do
583
627
  t = DataTable.from(%{
584
628
  | b | a |
585
629
  | d | c |
@@ -590,8 +634,8 @@ module Cucumber
590
634
  end
591
635
  end
592
636
 
593
- describe "#from" do
594
- it "should allow Array of Hash" do
637
+ describe '#from' do
638
+ it 'should allow Array of Hash' do
595
639
  t1 = DataTable.from([{'name' => 'aslak', 'male' => 'true'}])
596
640
  expect( t1.to_s(:indent => 12, :color => false) ).to eq %{
597
641
  | male | name |