cucumber 3.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +166 -19
  3. data/CONTRIBUTING.md +2 -18
  4. data/README.md +4 -5
  5. data/bin/cucumber +1 -1
  6. data/lib/autotest/cucumber_mixin.rb +34 -39
  7. data/lib/cucumber/cli/configuration.rb +5 -5
  8. data/lib/cucumber/cli/main.rb +12 -12
  9. data/lib/cucumber/cli/options.rb +62 -71
  10. data/lib/cucumber/cli/profile_loader.rb +49 -26
  11. data/lib/cucumber/configuration.rb +31 -23
  12. data/lib/cucumber/constantize.rb +2 -5
  13. data/lib/cucumber/deprecate.rb +31 -7
  14. data/lib/cucumber/errors.rb +5 -7
  15. data/lib/cucumber/events/envelope.rb +9 -0
  16. data/lib/cucumber/events/gherkin_source_parsed.rb +11 -0
  17. data/lib/cucumber/events/hook_test_step_created.rb +13 -0
  18. data/lib/cucumber/events/step_activated.rb +2 -1
  19. data/lib/cucumber/events/test_case_created.rb +13 -0
  20. data/lib/cucumber/events/test_case_ready.rb +12 -0
  21. data/lib/cucumber/events/test_step_created.rb +13 -0
  22. data/lib/cucumber/events/undefined_parameter_type.rb +10 -0
  23. data/lib/cucumber/events.rb +13 -6
  24. data/lib/cucumber/file_specs.rb +6 -6
  25. data/lib/cucumber/filters/activate_steps.rb +5 -3
  26. data/lib/cucumber/filters/broadcast_test_case_ready_event.rb +12 -0
  27. data/lib/cucumber/filters/prepare_world.rb +5 -9
  28. data/lib/cucumber/filters/quit.rb +1 -3
  29. data/lib/cucumber/filters/tag_limits/verifier.rb +2 -4
  30. data/lib/cucumber/filters.rb +1 -0
  31. data/lib/cucumber/formatter/ansicolor.rb +40 -45
  32. data/lib/cucumber/formatter/ast_lookup.rb +165 -0
  33. data/lib/cucumber/formatter/backtrace_filter.rb +9 -8
  34. data/lib/cucumber/formatter/console.rb +58 -66
  35. data/lib/cucumber/formatter/console_counts.rb +4 -9
  36. data/lib/cucumber/formatter/console_issues.rb +6 -3
  37. data/lib/cucumber/formatter/duration.rb +1 -1
  38. data/lib/cucumber/formatter/duration_extractor.rb +3 -1
  39. data/lib/cucumber/formatter/errors.rb +6 -0
  40. data/lib/cucumber/formatter/fanout.rb +2 -0
  41. data/lib/cucumber/formatter/html.rb +11 -598
  42. data/lib/cucumber/formatter/http_io.rb +1 -1
  43. data/lib/cucumber/formatter/ignore_missing_messages.rb +1 -1
  44. data/lib/cucumber/formatter/interceptor.rb +8 -28
  45. data/lib/cucumber/formatter/io.rb +1 -1
  46. data/lib/cucumber/formatter/json.rb +101 -115
  47. data/lib/cucumber/formatter/junit.rb +56 -56
  48. data/lib/cucumber/formatter/message.rb +22 -0
  49. data/lib/cucumber/formatter/message_builder.rb +255 -0
  50. data/lib/cucumber/formatter/pretty.rb +359 -153
  51. data/lib/cucumber/formatter/progress.rb +30 -32
  52. data/lib/cucumber/formatter/query/hook_by_test_step.rb +31 -0
  53. data/lib/cucumber/formatter/query/pickle_by_test.rb +26 -0
  54. data/lib/cucumber/formatter/query/pickle_step_by_test_step.rb +26 -0
  55. data/lib/cucumber/formatter/query/step_definitions_by_test_step.rb +40 -0
  56. data/lib/cucumber/formatter/query/test_case_started_by_test_case.rb +40 -0
  57. data/lib/cucumber/formatter/rerun.rb +22 -4
  58. data/lib/cucumber/formatter/stepdefs.rb +1 -2
  59. data/lib/cucumber/formatter/steps.rb +2 -3
  60. data/lib/cucumber/formatter/summary.rb +16 -8
  61. data/lib/cucumber/formatter/unicode.rb +15 -17
  62. data/lib/cucumber/formatter/usage.rb +11 -10
  63. data/lib/cucumber/gherkin/data_table_parser.rb +17 -6
  64. data/lib/cucumber/gherkin/formatter/ansi_escapes.rb +13 -17
  65. data/lib/cucumber/gherkin/formatter/escaping.rb +2 -2
  66. data/lib/cucumber/gherkin/steps_parser.rb +17 -8
  67. data/lib/cucumber/glue/dsl.rb +1 -1
  68. data/lib/cucumber/glue/hook.rb +34 -11
  69. data/lib/cucumber/glue/invoke_in_world.rb +13 -18
  70. data/lib/cucumber/glue/proto_world.rb +42 -33
  71. data/lib/cucumber/glue/registry_and_more.rb +42 -12
  72. data/lib/cucumber/glue/snippet.rb +23 -22
  73. data/lib/cucumber/glue/step_definition.rb +42 -19
  74. data/lib/cucumber/glue/world_factory.rb +1 -1
  75. data/lib/cucumber/hooks.rb +11 -11
  76. data/lib/cucumber/multiline_argument/data_table/diff_matrices.rb +1 -1
  77. data/lib/cucumber/multiline_argument/data_table.rb +97 -64
  78. data/lib/cucumber/multiline_argument/doc_string.rb +1 -1
  79. data/lib/cucumber/multiline_argument.rb +4 -6
  80. data/lib/cucumber/platform.rb +3 -3
  81. data/lib/cucumber/rake/task.rb +16 -16
  82. data/lib/cucumber/rspec/disable_option_parser.rb +9 -8
  83. data/lib/cucumber/running_test_case.rb +2 -53
  84. data/lib/cucumber/runtime/after_hooks.rb +8 -4
  85. data/lib/cucumber/runtime/before_hooks.rb +8 -4
  86. data/lib/cucumber/runtime/for_programming_languages.rb +4 -2
  87. data/lib/cucumber/runtime/step_hooks.rb +3 -2
  88. data/lib/cucumber/runtime/support_code.rb +13 -15
  89. data/lib/cucumber/runtime/user_interface.rb +6 -16
  90. data/lib/cucumber/runtime.rb +54 -58
  91. data/lib/cucumber/step_definition_light.rb +4 -3
  92. data/lib/cucumber/step_definitions.rb +2 -2
  93. data/lib/cucumber/step_match.rb +12 -11
  94. data/lib/cucumber/step_match_search.rb +2 -1
  95. data/lib/cucumber/term/ansicolor.rb +9 -9
  96. data/lib/cucumber/version +1 -1
  97. data/lib/cucumber.rb +1 -1
  98. metadata +221 -77
  99. data/lib/cucumber/formatter/cucumber.css +0 -286
  100. data/lib/cucumber/formatter/cucumber.sass +0 -247
  101. data/lib/cucumber/formatter/hook_query_visitor.rb +0 -42
  102. data/lib/cucumber/formatter/html_builder.rb +0 -121
  103. data/lib/cucumber/formatter/inline-js.js +0 -30
  104. data/lib/cucumber/formatter/jquery-min.js +0 -154
  105. data/lib/cucumber/formatter/json_pretty.rb +0 -11
  106. data/lib/cucumber/formatter/legacy_api/adapter.rb +0 -1028
  107. data/lib/cucumber/formatter/legacy_api/ast.rb +0 -394
  108. data/lib/cucumber/formatter/legacy_api/results.rb +0 -50
  109. data/lib/cucumber/formatter/legacy_api/runtime_facade.rb +0 -32
  110. data/lib/cucumber/step_argument.rb +0 -25
@@ -3,23 +3,27 @@
3
3
  module Cucumber
4
4
  class Runtime
5
5
  class AfterHooks
6
- def initialize(hooks, scenario)
6
+ def initialize(id_generator, hooks, scenario, event_bus)
7
7
  @hooks = hooks
8
8
  @scenario = scenario
9
+ @id_generator = id_generator
10
+ @event_bus = event_bus
9
11
  end
10
12
 
11
13
  def apply_to(test_case)
12
14
  test_case.with_steps(
13
- test_case.test_steps + after_hooks(test_case.source).reverse
15
+ test_case.test_steps + after_hooks.reverse
14
16
  )
15
17
  end
16
18
 
17
19
  private
18
20
 
19
- def after_hooks(source)
21
+ def after_hooks
20
22
  @hooks.map do |hook|
21
23
  action = ->(result) { hook.invoke('After', @scenario.with_result(result)) }
22
- Hooks.after_hook(source, hook.location, &action)
24
+ hook_step = Hooks.after_hook(@id_generator.new_id, hook.location, &action)
25
+ @event_bus.hook_test_step_created(hook_step, hook)
26
+ hook_step
23
27
  end
24
28
  end
25
29
  end
@@ -5,23 +5,27 @@ require 'cucumber/hooks'
5
5
  module Cucumber
6
6
  class Runtime
7
7
  class BeforeHooks
8
- def initialize(hooks, scenario)
8
+ def initialize(id_generator, hooks, scenario, event_bus)
9
9
  @hooks = hooks
10
10
  @scenario = scenario
11
+ @id_generator = id_generator
12
+ @event_bus = event_bus
11
13
  end
12
14
 
13
15
  def apply_to(test_case)
14
16
  test_case.with_steps(
15
- before_hooks(test_case.source) + test_case.test_steps
17
+ before_hooks + test_case.test_steps
16
18
  )
17
19
  end
18
20
 
19
21
  private
20
22
 
21
- def before_hooks(source)
23
+ def before_hooks
22
24
  @hooks.map do |hook|
23
25
  action_block = ->(result) { hook.invoke('Before', @scenario.with_result(result)) }
24
- Hooks.before_hook(source, hook.location, &action_block)
26
+ hook_step = Hooks.before_hook(@id_generator.new_id, hook.location, &action_block)
27
+ @event_bus.hook_test_step_created(hook_step, hook)
28
+ hook_step
25
29
  end
26
30
  end
27
31
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
- require 'cucumber/core/ast/doc_string'
4
+ require 'cucumber/core/test/doc_string'
5
5
 
6
6
  module Cucumber
7
7
  class Runtime
@@ -15,11 +15,13 @@ module Cucumber
15
15
  attr_reader :support_code
16
16
 
17
17
  def initialize(support_code, user_interface)
18
- @support_code, @user_interface = support_code, user_interface
18
+ @support_code = support_code
19
+ @user_interface = user_interface
19
20
  end
20
21
 
21
22
  def_delegators :@user_interface,
22
23
  :embed,
24
+ :attach,
23
25
  :ask,
24
26
  :puts,
25
27
  :features_paths,
@@ -3,8 +3,9 @@
3
3
  module Cucumber
4
4
  class Runtime
5
5
  class StepHooks
6
- def initialize(hooks)
6
+ def initialize(id_generator, hooks)
7
7
  @hooks = hooks
8
+ @id_generator = id_generator
8
9
  end
9
10
 
10
11
  def apply(test_steps)
@@ -18,7 +19,7 @@ module Cucumber
18
19
  def after_step_hooks(test_step)
19
20
  @hooks.map do |hook|
20
21
  action = ->(*args) { hook.invoke('AfterStep', [args, test_step]) }
21
- Hooks.after_step_hook(test_step.source, hook.location, &action)
22
+ Hooks.after_step_hook(@id_generator.new_id, test_step, hook.location, &action)
22
23
  end
23
24
  end
24
25
  end
@@ -22,19 +22,15 @@ module Cucumber
22
22
  end
23
23
 
24
24
  def step(step)
25
- location = Core::Ast::Location.of_caller
25
+ location = Core::Test::Location.of_caller
26
26
  @support_code.invoke_dynamic_step(step[:text], multiline_arg(step, location))
27
27
  end
28
28
 
29
29
  def multiline_arg(step, location)
30
- argument = step[:argument]
31
-
32
- if argument
33
- if argument[:type] == :DocString
34
- MultilineArgument.from(argument[:content], location, argument[:content_type])
35
- else
36
- MultilineArgument::DataTable.from(argument[:rows].map { |row| row[:cells].map { |cell| cell[:value] } })
37
- end
30
+ if !step[:doc_string].nil?
31
+ MultilineArgument.from(step[:doc_string][:content], location, step[:doc_string][:content_type])
32
+ elsif !step[:data_table].nil?
33
+ MultilineArgument::DataTable.from(step[:data_table][:rows].map { |row| row[:cells].map { |cell| cell[:value] } })
38
34
  else
39
35
  MultilineArgument.from(nil)
40
36
  end
@@ -62,8 +58,8 @@ module Cucumber
62
58
  # Given I have 8 cukes in my belly
63
59
  # Then I should not be thirsty
64
60
  # })
65
- def invoke_dynamic_steps(steps_text, i18n, _location)
66
- parser = Cucumber::Gherkin::StepsParser.new(StepInvoker.new(self), i18n.iso_code)
61
+ def invoke_dynamic_steps(steps_text, iso_code, _location)
62
+ parser = Cucumber::Gherkin::StepsParser.new(StepInvoker.new(self), iso_code)
67
63
  parser.parse(steps_text)
68
64
  end
69
65
 
@@ -108,26 +104,28 @@ module Cucumber
108
104
  def find_after_step_hooks(test_case)
109
105
  scenario = RunningTestCase.new(test_case)
110
106
  hooks = registry.hooks_for(:after_step, scenario)
111
- StepHooks.new hooks
107
+ StepHooks.new(@configuration.id_generator, hooks)
112
108
  end
113
109
 
114
110
  def apply_before_hooks(test_case)
111
+ return test_case if test_case.test_steps.empty?
115
112
  scenario = RunningTestCase.new(test_case)
116
113
  hooks = registry.hooks_for(:before, scenario)
117
- BeforeHooks.new(hooks, scenario).apply_to(test_case)
114
+ BeforeHooks.new(@configuration.id_generator, hooks, scenario, @configuration.event_bus).apply_to(test_case)
118
115
  end
119
116
 
120
117
  def apply_after_hooks(test_case)
118
+ return test_case if test_case.test_steps.empty?
121
119
  scenario = RunningTestCase.new(test_case)
122
120
  hooks = registry.hooks_for(:after, scenario)
123
- AfterHooks.new(hooks, scenario).apply_to(test_case)
121
+ AfterHooks.new(@configuration.id_generator, hooks, scenario, @configuration.event_bus).apply_to(test_case)
124
122
  end
125
123
 
126
124
  def find_around_hooks(test_case)
127
125
  scenario = RunningTestCase.new(test_case)
128
126
 
129
127
  registry.hooks_for(:around, scenario).map do |hook|
130
- Hooks.around_hook(test_case.source) do |run_scenario|
128
+ Hooks.around_hook do |run_scenario|
131
129
  hook.invoke('Around', scenario, &run_scenario)
132
130
  end
133
131
  end
@@ -7,14 +7,6 @@ module Cucumber
7
7
  module UserInterface
8
8
  attr_writer :visitor
9
9
 
10
- # Output +messages+ alongside the formatted output.
11
- # This is an alternative to using Kernel#puts - it will display
12
- # nicer, and in all outputs (in case you use several formatters)
13
- #
14
- def puts(*messages)
15
- @visitor.puts(*messages)
16
- end
17
-
18
10
  # Suspends execution and prompts +question+ to the console (STDOUT).
19
11
  # An operator (manual tester) can then enter a line of text and hit
20
12
  # <ENTER>. The entered text is returned, and both +question+ and
@@ -48,20 +40,18 @@ module Cucumber
48
40
  # be a path to a file, or if it's an image it may also be a Base64 encoded image.
49
41
  # The embedded data may or may not be ignored, depending on what kind of formatter(s) are active.
50
42
  #
51
- def embed(src, mime_type, label)
52
- @visitor.embed(src, mime_type, label)
43
+ def attach(src, media_type)
44
+ @visitor.attach(src, media_type)
53
45
  end
54
46
 
55
47
  private
56
48
 
57
49
  def mri_gets(timeout_seconds)
58
- begin
59
- Timeout.timeout(timeout_seconds) do
60
- STDIN.gets
61
- end
62
- rescue Timeout::Error
63
- nil
50
+ Timeout.timeout(timeout_seconds) do
51
+ STDIN.gets
64
52
  end
53
+ rescue Timeout::Error
54
+ nil
65
55
  end
66
56
 
67
57
  def jruby_gets(timeout_seconds)
@@ -1,8 +1,6 @@
1
- # -*- coding: utf-8 -*-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'fileutils'
5
- require 'multi_json'
6
4
  require 'cucumber/configuration'
7
5
  require 'cucumber/load_path'
8
6
  require 'cucumber/formatter/duration'
@@ -11,6 +9,8 @@ require 'cucumber/filters'
11
9
  require 'cucumber/formatter/fanout'
12
10
  require 'cucumber/gherkin/i18n'
13
11
  require 'cucumber/step_match_search'
12
+ require 'cucumber/messages'
13
+ require 'sys/uname'
14
14
 
15
15
  module Cucumber
16
16
  module FixRuby21Bug9285
@@ -19,8 +19,8 @@ module Cucumber
19
19
  end
20
20
  end
21
21
 
22
- class FileException < Exception
23
- attr :path
22
+ class FileException < RuntimeError
23
+ attr_reader :path
24
24
 
25
25
  def initialize(original_exception, path)
26
26
  super(original_exception)
@@ -31,7 +31,7 @@ module Cucumber
31
31
  class FileNotFoundException < FileException
32
32
  end
33
33
 
34
- class FeatureFolderNotFoundException < Exception
34
+ class FeatureFolderNotFoundException < RuntimeError
35
35
  def initialize(path)
36
36
  @path = path
37
37
  end
@@ -54,7 +54,6 @@ module Cucumber
54
54
  def initialize(configuration = Configuration.default)
55
55
  @configuration = Configuration.new(configuration)
56
56
  @support_code = SupportCode.new(self, @configuration)
57
- @results = Formatter::LegacyApi::Results.new
58
57
  end
59
58
 
60
59
  # Allows you to take an existing runtime and change its configuration
@@ -65,6 +64,10 @@ module Cucumber
65
64
 
66
65
  require 'cucumber/wire/plugin'
67
66
  def run!
67
+ @configuration.notify :envelope, Cucumber::Messages::Envelope.new(
68
+ meta: make_meta
69
+ )
70
+
68
71
  load_step_definitions
69
72
  install_wire_plugin
70
73
  fire_after_configuration_hook
@@ -72,7 +75,7 @@ module Cucumber
72
75
  self.visitor = report
73
76
 
74
77
  receiver = Test::Runner.new(@configuration.event_bus)
75
- compile features, receiver, filters
78
+ compile features, receiver, filters, @configuration.event_bus
76
79
  @configuration.notify :test_run_finished
77
80
  end
78
81
 
@@ -84,14 +87,6 @@ module Cucumber
84
87
  @configuration.dry_run?
85
88
  end
86
89
 
87
- def scenarios(status = nil)
88
- @results.scenarios(status)
89
- end
90
-
91
- def steps(status = nil)
92
- @results.steps(status)
93
- end
94
-
95
90
  def unmatched_step_definitions
96
91
  @support_code.unmatched_step_definitions
97
92
  end
@@ -107,13 +102,33 @@ module Cucumber
107
102
  # Returns Ast::DocString for +string_without_triple_quotes+.
108
103
  #
109
104
  def doc_string(string_without_triple_quotes, content_type = '', _line_offset = 0)
110
- location = Core::Ast::Location.of_caller
111
- Core::Ast::DocString.new(string_without_triple_quotes, content_type, location)
105
+ Core::Test::DocString.new(string_without_triple_quotes, content_type)
106
+ end
107
+
108
+ def make_meta
109
+ Cucumber::Messages::Meta.new(
110
+ protocol_version: Cucumber::Messages::VERSION,
111
+ implementation: Cucumber::Messages::Meta::Product.new(
112
+ name: 'cucumber-ruby',
113
+ version: Cucumber::VERSION
114
+ ),
115
+ runtime: Cucumber::Messages::Meta::Product.new(
116
+ name: RUBY_ENGINE,
117
+ version: RUBY_VERSION
118
+ ),
119
+ os: Cucumber::Messages::Meta::Product.new(
120
+ name: RbConfig::CONFIG['target_os'],
121
+ version: Sys::Uname.uname.version
122
+ ),
123
+ cpu: Cucumber::Messages::Meta::Product.new(
124
+ name: RbConfig::CONFIG['target_cpu']
125
+ )
126
+ )
112
127
  end
113
128
 
114
129
  private
115
130
 
116
- def fire_after_configuration_hook #:nodoc
131
+ def fire_after_configuration_hook #:nodoc:
117
132
  @support_code.fire_hook(:after_configuration, @configuration)
118
133
  end
119
134
 
@@ -143,14 +158,12 @@ module Cucumber
143
158
  end
144
159
 
145
160
  def initialize(path)
146
- begin
147
- @file = File.new(path)
148
- set_encoding
149
- rescue Errno::EACCES => e
150
- raise FileNotFoundException.new(e, File.expand_path(path))
151
- rescue Errno::ENOENT
152
- raise FeatureFolderNotFoundException.new(path)
153
- end
161
+ @file = File.new(path)
162
+ set_encoding
163
+ rescue Errno::EACCES => e
164
+ raise FileNotFoundException.new(e, File.expand_path(path))
165
+ rescue Errno::ENOENT
166
+ raise FeatureFolderNotFoundException, path
154
167
  end
155
168
 
156
169
  def read
@@ -162,7 +175,7 @@ module Cucumber
162
175
  def set_encoding
163
176
  @file.each do |line|
164
177
  if ENCODING_PATTERN =~ line
165
- @file.set_encoding $1
178
+ @file.set_encoding Regexp.last_match(1)
166
179
  break
167
180
  end
168
181
  break unless COMMENT_OR_EMPTY_LINE_PATTERN =~ line
@@ -171,9 +184,6 @@ module Cucumber
171
184
  end
172
185
  end
173
186
 
174
- require 'cucumber/formatter/legacy_api/adapter'
175
- require 'cucumber/formatter/legacy_api/runtime_facade'
176
- require 'cucumber/formatter/legacy_api/results'
177
187
  require 'cucumber/formatter/ignore_missing_messages'
178
188
  require 'cucumber/formatter/fail_fast'
179
189
  require 'cucumber/core/report/summary'
@@ -194,39 +204,26 @@ module Cucumber
194
204
 
195
205
  def formatters
196
206
  @formatters ||=
197
- @configuration.formatter_factories do |factory, formatter_options, path_or_io, options|
198
- create_formatter(factory, formatter_options, path_or_io, options)
207
+ @configuration.formatter_factories do |factory, formatter_options, path_or_io|
208
+ create_formatter(factory, formatter_options, path_or_io)
199
209
  end
200
210
  end
201
211
 
202
- def create_formatter(factory, formatter_options, path_or_io, cli_options)
203
- if !legacy_formatter?(factory)
204
- if accept_options?(factory)
205
- return factory.new(@configuration, formatter_options) if path_or_io.nil?
206
- return factory.new(@configuration.with_options(out_stream: path_or_io),
207
- formatter_options)
208
- else
209
- return factory.new(@configuration) if path_or_io.nil?
210
- return factory.new(@configuration.with_options(out_stream: path_or_io))
211
- end
212
+ def create_formatter(factory, formatter_options, path_or_io)
213
+ if accept_options?(factory)
214
+ return factory.new(@configuration, formatter_options) if path_or_io.nil?
215
+ factory.new(@configuration.with_options(out_stream: path_or_io),
216
+ formatter_options)
217
+ else
218
+ return factory.new(@configuration) if path_or_io.nil?
219
+ factory.new(@configuration.with_options(out_stream: path_or_io))
212
220
  end
213
- results = Formatter::LegacyApi::Results.new
214
- runtime_facade = Formatter::LegacyApi::RuntimeFacade.new(results, @support_code, @configuration)
215
- formatter = factory.new(runtime_facade, path_or_io, cli_options)
216
- Formatter::LegacyApi::Adapter.new(
217
- Formatter::IgnoreMissingMessages.new(formatter),
218
- results, @configuration
219
- )
220
221
  end
221
222
 
222
223
  def accept_options?(factory)
223
224
  factory.instance_method(:initialize).arity > 1
224
225
  end
225
226
 
226
- def legacy_formatter?(factory)
227
- factory.instance_method(:initialize).arity > 2
228
- end
229
-
230
227
  def failure?
231
228
  if @configuration.wip?
232
229
  summary_report.test_cases.total_passed > 0
@@ -237,7 +234,7 @@ module Cucumber
237
234
  public :failure?
238
235
 
239
236
  require 'cucumber/core/test/filters'
240
- def filters
237
+ def filters # rubocop:disable Metrics/AbcSize
241
238
  tag_expressions = @configuration.tag_expressions
242
239
  name_regexps = @configuration.name_regexps
243
240
  tag_limits = @configuration.tag_limits
@@ -250,14 +247,13 @@ module Cucumber
250
247
  # TODO: can we just use Glue::RegistryAndMore's step definitions directly?
251
248
  step_match_search = StepMatchSearch.new(@support_code.registry.method(:step_matches), @configuration)
252
249
  filters << Filters::ActivateSteps.new(step_match_search, @configuration)
253
- @configuration.filters.each do |filter|
254
- filters << filter
255
- end
250
+ @configuration.filters.each { |filter| filters << filter }
256
251
  unless configuration.dry_run?
257
252
  filters << Filters::ApplyAfterStepHooks.new(@support_code)
258
253
  filters << Filters::ApplyBeforeHooks.new(@support_code)
259
254
  filters << Filters::ApplyAfterHooks.new(@support_code)
260
255
  filters << Filters::ApplyAroundHooks.new(@support_code)
256
+ filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration)
261
257
  filters << Filters::BroadcastTestRunStartedEvent.new(@configuration)
262
258
  filters << Filters::Quit.new
263
259
  filters << Filters::Retry.new(@configuration)
@@ -273,7 +269,7 @@ module Cucumber
273
269
  end
274
270
 
275
271
  def install_wire_plugin
276
- Cucumber::Wire::Plugin.new(@configuration).install if @configuration.all_files_to_load.any? { |f| f =~ %r{\.wire$} }
272
+ Cucumber::Wire::Plugin.new(@configuration, @support_code.registry).install if @configuration.all_files_to_load.any? { |f| f =~ /\.wire$/ }
277
273
  end
278
274
 
279
275
  def log
@@ -9,11 +9,12 @@ module Cucumber
9
9
  attr_reader :regexp_source, :location
10
10
 
11
11
  def initialize(regexp_source, location)
12
- @regexp_source, @location = regexp_source, location
12
+ @regexp_source = regexp_source
13
+ @location = location
13
14
  end
14
15
 
15
- def eql?(o)
16
- regexp_source == o.regexp_source && location == o.location
16
+ def eql?(other)
17
+ regexp_source == other.regexp_source && location == other.location
17
18
  end
18
19
 
19
20
  def hash
@@ -8,8 +8,8 @@ module Cucumber
8
8
  @support_code.load_files_from_paths(configuration.autoload_code_paths)
9
9
  end
10
10
 
11
- def to_json
12
- @support_code.step_definitions.map(&:to_hash).to_json
11
+ def to_json(obj = nil)
12
+ @support_code.step_definitions.map(&:to_hash).to_json(obj)
13
13
  end
14
14
  end
15
15
  end
@@ -9,7 +9,9 @@ module Cucumber
9
9
 
10
10
  def initialize(step_definition, step_name, step_arguments)
11
11
  raise "step_arguments can't be nil (but it can be an empty array)" if step_arguments.nil?
12
- @step_definition, @name_to_match, @step_arguments = step_definition, step_name, step_arguments
12
+ @step_definition = step_definition
13
+ @name_to_match = step_name
14
+ @step_arguments = step_arguments
13
15
  end
14
16
 
15
17
  def args
@@ -21,7 +23,7 @@ module Cucumber
21
23
 
22
24
  def activate(test_step)
23
25
  test_step.with_action(@step_definition.location) do
24
- invoke(MultilineArgument.from_core(test_step.source.last.multiline_arg))
26
+ invoke(MultilineArgument.from_core(test_step.multiline_arg))
25
27
  end
26
28
  end
27
29
 
@@ -46,7 +48,7 @@ module Cucumber
46
48
  #
47
49
  # lambda { |param| "[#{param}]" }
48
50
  #
49
- def format_args(format = lambda { |a| a }, &proc)
51
+ def format_args(format = ->(a) { a }, &proc)
50
52
  replace_arguments(@name_to_match, @step_arguments, format, &proc)
51
53
  end
52
54
 
@@ -75,7 +77,7 @@ module Cucumber
75
77
 
76
78
  replacement = if block_given?
77
79
  yield(group.value)
78
- elsif Proc === format
80
+ elsif Proc == format.class
79
81
  format.call(group.value)
80
82
  else
81
83
  format % group.value
@@ -95,13 +97,13 @@ module Cucumber
95
97
  private
96
98
 
97
99
  def deep_clone_args
98
- Marshal.load( Marshal.dump( args ) )
100
+ Marshal.load(Marshal.dump(args))
99
101
  end
100
102
  end
101
103
 
102
104
  class SkippingStepMatch
103
105
  def activate(test_step)
104
- return test_step.with_action { raise Core::Test::Result::Skipped.new }
106
+ test_step.with_action { raise Core::Test::Result::Skipped }
105
107
  end
106
108
  end
107
109
 
@@ -123,8 +125,7 @@ module Cucumber
123
125
  end
124
126
 
125
127
  def file_colon_line
126
- raise "No file:line for #{@step}" unless @step.file_colon_line
127
- @step.file_colon_line
128
+ location.to_s
128
129
  end
129
130
 
130
131
  def backtrace_line
@@ -132,7 +133,7 @@ module Cucumber
132
133
  end
133
134
 
134
135
  def text_length
135
- @step.text_length
136
+ @step.text.length
136
137
  end
137
138
 
138
139
  def step_arguments
@@ -141,7 +142,7 @@ module Cucumber
141
142
 
142
143
  def activate(test_step)
143
144
  # noop
144
- return test_step
145
+ test_step
145
146
  end
146
147
  end
147
148
 
@@ -151,7 +152,7 @@ module Cucumber
151
152
  end
152
153
 
153
154
  def activate(test_step)
154
- return test_step.with_action { raise @error }
155
+ test_step.with_action { raise @error }
155
156
  end
156
157
  end
157
158
  end
@@ -13,7 +13,8 @@ module Cucumber
13
13
 
14
14
  class AssertUnambiguousMatch
15
15
  def initialize(search, configuration)
16
- @search, @configuration = search, configuration
16
+ @search = search
17
+ @configuration = configuration
17
18
  end
18
19
 
19
20
  def call(step_name)
@@ -35,7 +35,7 @@ module Cucumber
35
35
  [:on_magenta, 45],
36
36
  [:on_cyan, 46],
37
37
  [:on_white, 47]
38
- ]
38
+ ].freeze
39
39
 
40
40
  ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
41
41
  # :startdoc:
@@ -54,8 +54,9 @@ module Cucumber
54
54
  end
55
55
  self.coloring = true
56
56
 
57
+ # rubocop:disable Security/Eval
57
58
  ATTRIBUTES.each do |c, v|
58
- eval %Q{
59
+ eval <<-END_EVAL, binding, __FILE__, __LINE__ + 1
59
60
  def #{c}(string = nil)
60
61
  result = String.new
61
62
  result << "\e[#{v}m" if Cucumber::Term::ANSIColor.coloring?
@@ -71,23 +72,23 @@ module Cucumber
71
72
  result << "\e[0m" if Cucumber::Term::ANSIColor.coloring?
72
73
  result
73
74
  end
74
- }
75
+ END_EVAL
75
76
  end
77
+ # rubocop:enable Security/Eval
76
78
 
77
79
  # Regular expression that is used to scan for ANSI-sequences while
78
80
  # uncoloring strings.
79
81
  COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/
80
82
 
81
83
  def self.included(klass)
82
- if klass == String
83
- ATTRIBUTES.delete(:clear)
84
- ATTRIBUTE_NAMES.delete(:clear)
85
- end
84
+ return unless klass == String
85
+ ATTRIBUTES.delete(:clear)
86
+ ATTRIBUTE_NAMES.delete(:clear)
86
87
  end
87
88
 
88
89
  # Returns an uncolored version of the string, that is all
89
90
  # ANSI-sequences are stripped from the string.
90
- def uncolored(string = nil) # :yields:
91
+ def uncolored(string = nil)
91
92
  if block_given?
92
93
  yield.gsub(COLORED_REGEXP, '')
93
94
  elsif string
@@ -105,7 +106,6 @@ module Cucumber
105
106
  def attributes
106
107
  ATTRIBUTE_NAMES
107
108
  end
108
- extend self
109
109
  end
110
110
  end
111
111
  end
data/lib/cucumber/version CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 4.0.0
data/lib/cucumber.rb CHANGED
@@ -10,7 +10,7 @@ require 'cucumber/term/ansicolor'
10
10
 
11
11
  module Cucumber
12
12
  class << self
13
- attr_accessor :wants_to_quit
13
+ attr_accessor :wants_to_quit, :use_legacy_autoloader
14
14
 
15
15
  def logger
16
16
  return @log if @log