cucumber 11.0.0 → 11.1.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -6
  3. data/VERSION +1 -1
  4. data/lib/cucumber/cli/main.rb +22 -0
  5. data/lib/cucumber/configuration.rb +4 -0
  6. data/lib/cucumber/events/base.rb +25 -0
  7. data/lib/cucumber/events/envelope.rb +11 -2
  8. data/lib/cucumber/events/gherkin_source_parsed.rb +12 -3
  9. data/lib/cucumber/events/gherkin_source_read.rb +11 -3
  10. data/lib/cucumber/events/hook_test_step_created.rb +12 -2
  11. data/lib/cucumber/events/step_activated.rb +13 -7
  12. data/lib/cucumber/events/step_definition_registered.rb +12 -4
  13. data/lib/cucumber/events/test_case_created.rb +11 -3
  14. data/lib/cucumber/events/test_case_finished.rb +12 -4
  15. data/lib/cucumber/events/test_case_ready.rb +10 -4
  16. data/lib/cucumber/events/test_case_started.rb +11 -2
  17. data/lib/cucumber/events/test_run_finished.rb +10 -3
  18. data/lib/cucumber/events/test_run_hook_finished.rb +11 -3
  19. data/lib/cucumber/events/test_run_hook_started.rb +10 -1
  20. data/lib/cucumber/events/test_run_started.rb +11 -2
  21. data/lib/cucumber/events/test_step_created.rb +12 -2
  22. data/lib/cucumber/events/test_step_finished.rb +12 -2
  23. data/lib/cucumber/events/test_step_started.rb +11 -2
  24. data/lib/cucumber/events/undefined_parameter_type.rb +11 -3
  25. data/lib/cucumber/filters/fire_before_all_hooks.rb +36 -0
  26. data/lib/cucumber/formatter/console.rb +15 -7
  27. data/lib/cucumber/formatter/console_issues.rb +5 -5
  28. data/lib/cucumber/formatter/fail_fast.rb +3 -4
  29. data/lib/cucumber/formatter/global_hooks_summary.rb +36 -0
  30. data/lib/cucumber/formatter/json.rb +5 -3
  31. data/lib/cucumber/formatter/junit.rb +4 -6
  32. data/lib/cucumber/formatter/message.rb +7 -4
  33. data/lib/cucumber/formatter/message_builder.rb +207 -205
  34. data/lib/cucumber/formatter/pretty.rb +2 -5
  35. data/lib/cucumber/formatter/progress.rb +0 -2
  36. data/lib/cucumber/formatter/rerun.rb +10 -4
  37. data/lib/cucumber/formatter/usage.rb +1 -2
  38. data/lib/cucumber/glue/proto_world.rb +6 -4
  39. data/lib/cucumber/glue/registry_and_more.rb +98 -9
  40. data/lib/cucumber/runtime/user_interface.rb +2 -2
  41. data/lib/cucumber/runtime.rb +28 -9
  42. metadata +9 -14
  43. data/lib/cucumber/formatter/errors.rb +0 -9
  44. data/lib/cucumber/formatter/query/hook_by_test_step.rb +0 -34
  45. data/lib/cucumber/formatter/query/pickle_by_test.rb +0 -28
  46. data/lib/cucumber/formatter/query/step_definitions_by_test_step.rb +0 -42
  47. data/lib/cucumber/formatter/query/test_case_started_by_test_case.rb +0 -45
@@ -93,10 +93,12 @@ module Cucumber
93
93
  if File.file?(file)
94
94
  media_type = MiniMime.lookup_by_filename(file)&.content_type if media_type.nil?
95
95
  file = File.read(file, mode: 'rb')
96
+ streamed_file = true
96
97
  end
97
- super
98
+ # We pass in the concept of whether the file is streamed to ensure that the envelope encoding is correct
99
+ super(file, media_type, filename, streamed_file)
98
100
  rescue StandardError
99
- super
101
+ super(file, media_type, filename, streamed_file)
100
102
  end
101
103
 
102
104
  # Mark the matched step as pending.
@@ -153,8 +155,8 @@ module Cucumber
153
155
  runtime.ask(question, timeout_seconds)
154
156
  end
155
157
 
156
- define_method(:attach) do |file, media_type, filename|
157
- runtime.attach(file, media_type, filename)
158
+ define_method(:attach) do |file, media_type, filename, streamed_file|
159
+ runtime.attach(file, media_type, filename, streamed_file)
158
160
  end
159
161
 
160
162
  # Prints the list of modules that are included in the World
@@ -4,6 +4,8 @@ require 'cucumber/cucumber_expressions/parameter_type_registry'
4
4
  require 'cucumber/cucumber_expressions/cucumber_expression'
5
5
  require 'cucumber/cucumber_expressions/regular_expression'
6
6
  require 'cucumber/cucumber_expressions/cucumber_expression_generator'
7
+ require 'cucumber/messages/helpers/time_conversion'
8
+
7
9
  require 'cucumber/glue/dsl'
8
10
  require 'cucumber/glue/snippet'
9
11
  require 'cucumber/glue/hook'
@@ -13,6 +15,7 @@ require 'cucumber/glue/world_factory'
13
15
  require 'cucumber/gherkin/i18n'
14
16
  require 'multi_test'
15
17
  require 'cucumber/step_match'
18
+ require 'cucumber/events/base'
16
19
  require 'cucumber/events/step_definition_registered'
17
20
 
18
21
  module Cucumber
@@ -48,6 +51,8 @@ module Cucumber
48
51
  class RegistryAndMore
49
52
  attr_reader :current_world, :step_definitions
50
53
 
54
+ include Cucumber::Messages::Helpers::TimeConversion
55
+
51
56
  all_keywords = ::Gherkin::DIALECTS.keys.map do |dialect_name|
52
57
  dialect = ::Gherkin::Dialect.for(dialect_name)
53
58
  dialect.given_keywords + dialect.when_keywords + dialect.then_keywords + dialect.and_keywords + dialect.but_keywords
@@ -98,13 +103,20 @@ module Cucumber
98
103
  def register_rb_step_definition(string_or_regexp, proc_or_sym, options)
99
104
  step_definition = StepDefinition.new(@configuration.id_generator.new_id, self, string_or_regexp, proc_or_sym, options)
100
105
  @step_definitions << step_definition
101
- @configuration.notify :step_definition_registered, step_definition
106
+ @configuration.notify(:step_definition_registered, step_definition)
107
+ @configuration.notify(:envelope, step_definition.to_envelope)
102
108
  step_definition
103
109
  rescue Cucumber::CucumberExpressions::UndefinedParameterTypeError => e
104
- # TODO: add a way to extract the parameter type directly from the error.
105
- type_name = e.message.match(/^Undefined parameter type ['|{](.*)['|}].?$/)[1]
106
-
107
- @configuration.notify :undefined_parameter_type, type_name, string_or_regexp
110
+ @configuration.notify(:undefined_parameter_type, e.undefined_parameter_type_name, string_or_regexp)
111
+ # Move the below code into cucumber-expressions. Once done. Switch the line for
112
+ # @configuration.notify(:envelope, e.to_envelope(string_or_regexp))
113
+ to_envelope = Cucumber::Messages::Envelope.new(
114
+ undefined_parameter_type: Cucumber::Messages::UndefinedParameterType.new(
115
+ name: e.undefined_parameter_type_name,
116
+ expression: string_or_regexp
117
+ )
118
+ )
119
+ @configuration.notify(:envelope, to_envelope)
108
120
  end
109
121
 
110
122
  def build_rb_world_factory(world_modules, namespaced_world_modules, proc)
@@ -131,7 +143,7 @@ module Cucumber
131
143
 
132
144
  def begin_scenario(test_case)
133
145
  @current_world = WorldFactory.new(@world_proc).create_world
134
- @current_world.extend(ProtoWorld.for(@runtime, test_case.language))
146
+ @current_world.extend(ProtoWorld.for(@runtime, test_case&.language))
135
147
  MultiTest.extend_with_best_assertion_library(@current_world)
136
148
  @current_world.add_modules!(@world_modules || [], @namespaced_world_modules || {})
137
149
  end
@@ -147,15 +159,27 @@ module Cucumber
147
159
  end
148
160
 
149
161
  def before_all
162
+ set_up_world_for_global_hooks
163
+ all_succeeded = true
164
+ # Run each `BeforeAll` hook. Ensuring that we store the overall result as the worst status
150
165
  hooks[:before_all].each do |hook|
151
- invoke_run_hook(hook, 'BeforeAll')
166
+ result = invoke_run_hook(hook, 'BeforeAll')
167
+ all_succeeded = false unless result
152
168
  end
169
+ @current_world = nil
170
+ all_succeeded
153
171
  end
154
172
 
155
173
  def after_all
174
+ set_up_world_for_global_hooks
175
+ all_succeeded = true
176
+ # Run each `AfterAll` hook. Ensuring that we store the overall result as the worst status
156
177
  hooks[:after_all].each do |hook|
157
- invoke_run_hook(hook, 'AfterAll')
178
+ result = invoke_run_hook(hook, 'AfterAll')
179
+ all_succeeded = false unless result
158
180
  end
181
+ @current_world = nil
182
+ all_succeeded
159
183
  end
160
184
 
161
185
  def add_hook(type, hook)
@@ -182,16 +206,76 @@ module Cucumber
182
206
 
183
207
  def invoke_run_hook(hook, pseudo_method)
184
208
  @configuration.notify(:test_run_hook_started, hook)
209
+
210
+ current_test_run_hook_started_id = @configuration.id_generator.new_id
211
+ started_envelope = test_run_hook_started_envelope(hook, current_test_run_hook_started_id)
212
+ @configuration.notify(:envelope, started_envelope)
213
+
185
214
  timer = Core::Test::Timer.new.start
186
215
  begin
187
216
  hook.invoke(pseudo_method, [])
188
217
  @configuration.notify(:test_run_hook_finished, hook, Core::Test::Result::Passed.new(timer.duration))
218
+ finished_envelope = test_run_hook_finished_envelope(Core::Test::Result::Passed.new(timer.duration), current_test_run_hook_started_id)
219
+ @configuration.notify(:envelope, finished_envelope)
220
+ true
189
221
  rescue StandardError => e
190
222
  @configuration.notify(:test_run_hook_finished, hook, Core::Test::Result::Failed.new(timer.duration, e))
191
- raise
223
+ finished_envelope = test_run_hook_finished_envelope(Core::Test::Result::Failed.new(timer.duration, e), current_test_run_hook_started_id)
224
+ @configuration.notify(:envelope, finished_envelope)
225
+ false
192
226
  end
193
227
  end
194
228
 
229
+ def test_run_hook_started_envelope(hook, id)
230
+ Cucumber::Messages::Envelope.new(
231
+ test_run_hook_started: Cucumber::Messages::TestRunHookStarted.new(
232
+ id: id,
233
+ hook_id: hook.id,
234
+ test_run_started_id: @configuration.test_run_started_id,
235
+ timestamp: time_to_timestamp(Time.now)
236
+ )
237
+ )
238
+ end
239
+
240
+ def test_run_hook_finished_envelope(test_result, test_run_hook_started_id)
241
+ result = test_result
242
+ result_message = result.to_message
243
+
244
+ if result.failed?
245
+ result_message = Cucumber::Messages::TestStepResult.new(
246
+ status: result_message.status,
247
+ duration: result_message.duration,
248
+ message: create_error_message(result.exception),
249
+ exception: create_exception_object(result, result.exception)
250
+ )
251
+ end
252
+
253
+ Cucumber::Messages::Envelope.new(
254
+ test_run_hook_finished: Cucumber::Messages::TestRunHookFinished.new(
255
+ test_run_hook_started_id: test_run_hook_started_id,
256
+ timestamp: time_to_timestamp(Time.now),
257
+ result: result_message
258
+ )
259
+ )
260
+ end
261
+
262
+ def create_error_message(message_element)
263
+ <<~ERROR_MESSAGE
264
+ #{message_element.message} (#{message_element.class})
265
+ #{message_element.backtrace}
266
+ ERROR_MESSAGE
267
+ end
268
+
269
+ def create_exception_object(result, message_element)
270
+ return unless result.failed?
271
+
272
+ Cucumber::Messages::Exception.new(
273
+ type: message_element.class,
274
+ message: message_element.message,
275
+ stack_trace: message_element.backtrace.join("\n")
276
+ )
277
+ end
278
+
195
279
  def parameter_type_envelope(parameter_type)
196
280
  # TODO: should this be moved to Cucumber::Expression::ParameterType#to_envelope ??
197
281
  # Note: that would mean that cucumber-expression would depend on cucumber-messages
@@ -221,6 +305,11 @@ module Cucumber
221
305
  def hooks
222
306
  @hooks ||= Hash.new { |h, k| h[k] = [] }
223
307
  end
308
+
309
+ def set_up_world_for_global_hooks
310
+ # We don't need a language as we're just creating a world object to attach the BeforeAll / AfterAll hooks to
311
+ begin_scenario(nil)
312
+ end
224
313
  end
225
314
  end
226
315
  end
@@ -41,8 +41,8 @@ module Cucumber
41
41
  # be a path to a file, or if it's an image it may also be a Base64 encoded image.
42
42
  # The embedded data may or may not be ignored, depending on what kind of formatter(s) are active.
43
43
  #
44
- def attach(src, media_type, filename)
45
- @visitor.attach(src, media_type, filename)
44
+ def attach(src, media_type, filename, streamed_file)
45
+ @visitor.attach(src, media_type, filename, streamed_file)
46
46
  end
47
47
 
48
48
  private
@@ -72,15 +72,13 @@ module Cucumber
72
72
 
73
73
  load_step_definitions
74
74
  fire_install_plugin_hook
75
- fire_before_all_hook unless dry_run?
76
75
  # TODO: can we remove this state?
77
76
  self.visitor = report
78
77
 
79
78
  receiver = Test::Runner.new(@configuration.event_bus)
80
79
  compile features, receiver, filters, @configuration.event_bus
81
- @configuration.notify :test_run_finished, !failure?
82
-
83
80
  fire_after_all_hook unless dry_run?
81
+ @configuration.notify :test_run_finished, !failure?
84
82
  end
85
83
 
86
84
  def features_paths
@@ -113,7 +111,7 @@ module Cucumber
113
111
  if @configuration.wip?
114
112
  summary_report.test_cases.total_passed.positive?
115
113
  else
116
- !summary_report.ok?(strict: @configuration.strict)
114
+ !summary_report.ok?(strict: @configuration.strict) || !global_hooks_summary_report.ok?
117
115
  end
118
116
  end
119
117
 
@@ -123,10 +121,6 @@ module Cucumber
123
121
  @support_code.fire_hook(:install_plugin, @configuration, registry_wrapper)
124
122
  end
125
123
 
126
- def fire_before_all_hook # :nodoc:
127
- @support_code.fire_hook(:before_all)
128
- end
129
-
130
124
  def fire_after_all_hook # :nodoc:
131
125
  @support_code.fire_hook(:after_all)
132
126
  end
@@ -136,6 +130,22 @@ module Cucumber
136
130
  @features ||= feature_files.map do |path|
137
131
  source = NormalisedEncodingFile.read(path)
138
132
  @configuration.notify :gherkin_source_read, path, source
133
+
134
+ # TODO: When core is v17+ switch the below code out to the following
135
+ # Cucumber::Core::Gherkin::Document.new(path, source).tap do |document|
136
+ # @configuration.notify(:envelope, document.to_envelope)
137
+ # end
138
+ to_envelope =
139
+ Cucumber::Messages::Envelope.new(
140
+ source: Cucumber::Messages::Source.new(
141
+ uri: path,
142
+ data: source,
143
+ media_type: 'text/x.cucumber.gherkin+plain'
144
+ )
145
+ )
146
+
147
+ @configuration.notify(:envelope, to_envelope)
148
+
139
149
  Cucumber::Core::Gherkin::Document.new(path, source)
140
150
  end
141
151
  end
@@ -191,16 +201,24 @@ module Cucumber
191
201
  def report
192
202
  return @report if @report
193
203
 
194
- reports = [summary_report] + formatters
204
+ reports = [message_builder, summary_report, global_hooks_summary_report] + formatters
195
205
  reports << fail_fast_report if @configuration.fail_fast?
196
206
  reports << publish_banner_printer unless @configuration.publish_quiet?
197
207
  @report ||= Formatter::Fanout.new(reports)
198
208
  end
199
209
 
210
+ def message_builder
211
+ @message_builder ||= Formatter::MessageBuilder.new(@configuration)
212
+ end
213
+
200
214
  def summary_report
201
215
  @summary_report ||= Core::Report::Summary.new(@configuration.event_bus)
202
216
  end
203
217
 
218
+ def global_hooks_summary_report
219
+ @global_hooks_summary_report ||= Formatter::GlobalHooksSummary.new(@configuration)
220
+ end
221
+
204
222
  def fail_fast_report
205
223
  @fail_fast_report ||= Formatter::FailFast.new(@configuration)
206
224
  end
@@ -256,6 +274,7 @@ module Cucumber
256
274
  filters << Filters::ApplyAfterHooks.new(@support_code)
257
275
  filters << Filters::ApplyAroundHooks.new(@support_code)
258
276
  filters << Filters::BroadcastTestRunStartedEvent.new(@configuration)
277
+ filters << Filters::FireBeforeAllHooks.new(@support_code)
259
278
  filters << Filters::Quit.new
260
279
  end
261
280
 
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.0
4
+ version: 11.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
8
8
  - Matt Wynne
9
9
  - Steve Tooke
10
10
  - Luke Hill
11
- autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2026-04-14 00:00:00.000000000 Z
13
+ date: 1980-01-02 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: base64
@@ -197,14 +196,14 @@ dependencies:
197
196
  requirements:
198
197
  - - "~>"
199
198
  - !ruby/object:Gem::Version
200
- version: '22.0'
199
+ version: '24.0'
201
200
  type: :development
202
201
  prerelease: false
203
202
  version_requirements: !ruby/object:Gem::Requirement
204
203
  requirements:
205
204
  - - "~>"
206
205
  - !ruby/object:Gem::Version
207
- version: '22.0'
206
+ version: '24.0'
208
207
  - !ruby/object:Gem::Dependency
209
208
  name: nokogiri
210
209
  requirement: !ruby/object:Gem::Requirement
@@ -354,6 +353,7 @@ files:
354
353
  - lib/cucumber/encoding.rb
355
354
  - lib/cucumber/errors.rb
356
355
  - lib/cucumber/events.rb
356
+ - lib/cucumber/events/base.rb
357
357
  - lib/cucumber/events/envelope.rb
358
358
  - lib/cucumber/events/gherkin_source_parsed.rb
359
359
  - lib/cucumber/events/gherkin_source_read.rb
@@ -381,6 +381,7 @@ files:
381
381
  - lib/cucumber/filters/apply_before_hooks.rb
382
382
  - lib/cucumber/filters/broadcast_test_case_ready_event.rb
383
383
  - lib/cucumber/filters/broadcast_test_run_started_event.rb
384
+ - lib/cucumber/filters/fire_before_all_hooks.rb
384
385
  - lib/cucumber/filters/gated_receiver.rb
385
386
  - lib/cucumber/filters/prepare_world.rb
386
387
  - lib/cucumber/filters/quit.rb
@@ -400,9 +401,9 @@ files:
400
401
  - lib/cucumber/formatter/curl_option_parser.rb
401
402
  - lib/cucumber/formatter/duration.rb
402
403
  - lib/cucumber/formatter/duration_extractor.rb
403
- - lib/cucumber/formatter/errors.rb
404
404
  - lib/cucumber/formatter/fail_fast.rb
405
405
  - lib/cucumber/formatter/fanout.rb
406
+ - lib/cucumber/formatter/global_hooks_summary.rb
406
407
  - lib/cucumber/formatter/html.rb
407
408
  - lib/cucumber/formatter/http_io.rb
408
409
  - lib/cucumber/formatter/ignore_missing_messages.rb
@@ -416,10 +417,6 @@ files:
416
417
  - lib/cucumber/formatter/pretty.rb
417
418
  - lib/cucumber/formatter/progress.rb
418
419
  - lib/cucumber/formatter/publish_banner_printer.rb
419
- - lib/cucumber/formatter/query/hook_by_test_step.rb
420
- - lib/cucumber/formatter/query/pickle_by_test.rb
421
- - lib/cucumber/formatter/query/step_definitions_by_test_step.rb
422
- - lib/cucumber/formatter/query/test_case_started_by_test_case.rb
423
420
  - lib/cucumber/formatter/rerun.rb
424
421
  - lib/cucumber/formatter/stepdefs.rb
425
422
  - lib/cucumber/formatter/steps.rb
@@ -484,7 +481,6 @@ metadata:
484
481
  mailing_list_uri: https://groups.google.com/forum/#!forum/cukes
485
482
  source_code_uri: https://github.com/cucumber/cucumber-ruby
486
483
  funding_uri: https://opencollective.com/cucumber
487
- post_install_message:
488
484
  rdoc_options:
489
485
  - "--charset=UTF-8"
490
486
  require_paths:
@@ -500,8 +496,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
500
496
  - !ruby/object:Gem::Version
501
497
  version: 3.2.8
502
498
  requirements: []
503
- rubygems_version: 3.4.20
504
- signing_key:
499
+ rubygems_version: 4.0.10
505
500
  specification_version: 4
506
- summary: cucumber-11.0.0
501
+ summary: cucumber-11.1.0
507
502
  test_files: []
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cucumber
4
- module Formatter
5
- class TestCaseUnknownError < StandardError; end
6
-
7
- class TestStepUnknownError < StandardError; end
8
- end
9
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cucumber/formatter/errors'
4
-
5
- module Cucumber
6
- module Formatter
7
- module Query
8
- class HookByTestStep
9
- def initialize(config)
10
- @hook_id_by_test_step_id = {}
11
-
12
- config.on_event :test_step_created, &method(:on_test_step_created)
13
- config.on_event :hook_test_step_created, &method(:on_hook_test_step_created)
14
- end
15
-
16
- def hook_id(test_step)
17
- return @hook_id_by_test_step_id[test_step.id] if @hook_id_by_test_step_id.key?(test_step.id)
18
-
19
- raise TestStepUnknownError, "No hook found for #{test_step.id} }. Known: #{@hook_id_by_test_step_id.keys}"
20
- end
21
-
22
- private
23
-
24
- def on_test_step_created(event)
25
- @hook_id_by_test_step_id[event.test_step.id] = nil
26
- end
27
-
28
- def on_hook_test_step_created(event)
29
- @hook_id_by_test_step_id[event.test_step.id] = event.hook.id
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cucumber/formatter/errors'
4
-
5
- module Cucumber
6
- module Formatter
7
- module Query
8
- class PickleByTest
9
- def initialize(config)
10
- @pickle_id_by_test_case_id = {}
11
- config.on_event :test_case_created, &method(:on_test_case_created)
12
- end
13
-
14
- def pickle_id(test_case)
15
- return @pickle_id_by_test_case_id[test_case.id] if @pickle_id_by_test_case_id.key?(test_case.id)
16
-
17
- raise TestCaseUnknownError, "No pickle found for #{test_case.id} }. Known: #{@pickle_id_by_test_case_id.keys}"
18
- end
19
-
20
- private
21
-
22
- def on_test_case_created(event)
23
- @pickle_id_by_test_case_id[event.test_case.id] = event.pickle.id
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cucumber/formatter/errors'
4
-
5
- module Cucumber
6
- module Formatter
7
- module Query
8
- class StepDefinitionsByTestStep
9
- def initialize(config)
10
- @step_definition_ids_by_test_step_id = {}
11
- @step_match_arguments_by_test_step_id = {}
12
-
13
- config.on_event :test_step_created, &method(:on_test_step_created)
14
- config.on_event :step_activated, &method(:on_step_activated)
15
- end
16
-
17
- def step_definition_ids(test_step)
18
- return @step_definition_ids_by_test_step_id[test_step.id] if @step_definition_ids_by_test_step_id.key?(test_step.id)
19
-
20
- raise TestStepUnknownError, "No step definition found for #{test_step.id} }. Known: #{@step_definition_ids_by_test_step_id.keys}"
21
- end
22
-
23
- def step_match_arguments(test_step)
24
- return @step_match_arguments_by_test_step_id[test_step.id] if @step_match_arguments_by_test_step_id.key?(test_step.id)
25
-
26
- raise TestStepUnknownError, "No step match arguments found for #{test_step.id} }. Known: #{@step_match_arguments_by_test_step_id.keys}"
27
- end
28
-
29
- private
30
-
31
- def on_test_step_created(event)
32
- @step_definition_ids_by_test_step_id[event.test_step.id] = []
33
- end
34
-
35
- def on_step_activated(event)
36
- @step_definition_ids_by_test_step_id[event.test_step.id] << event.step_match.step_definition.id
37
- @step_match_arguments_by_test_step_id[event.test_step.id] = event.step_match.step_arguments
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cucumber/formatter/errors'
4
-
5
- module Cucumber
6
- module Formatter
7
- module Query
8
- class TestCaseStartedByTestCase
9
- def initialize(config)
10
- @config = config
11
- config.on_event :test_case_created, &method(:on_test_case_created)
12
- config.on_event :test_case_started, &method(:on_test_case_started)
13
-
14
- @attempts_by_test_case_id = {}
15
- @test_case_started_id_by_test_case_id = {}
16
- end
17
-
18
- def attempt_by_test_case(test_case)
19
- raise TestCaseUnknownError, "No test case found for #{test_case.id} }. Known: #{@attempts_by_test_case_id.keys}" unless @attempts_by_test_case_id.key?(test_case.id)
20
-
21
- @attempts_by_test_case_id[test_case.id]
22
- end
23
-
24
- def test_case_started_id_by_test_case(test_case)
25
- raise TestCaseUnknownError, "No test case found for #{test_case.id} }. Known: #{@test_case_started_id_by_test_case_id.keys}" unless @test_case_started_id_by_test_case_id.key?(test_case.id)
26
-
27
- @test_case_started_id_by_test_case_id[test_case.id]
28
- end
29
-
30
- private
31
-
32
- def on_test_case_created(event)
33
- @attempts_by_test_case_id[event.test_case.id] = 0
34
- @test_case_started_id_by_test_case_id[event.test_case.id] = nil
35
- end
36
-
37
- def on_test_case_started(event)
38
- # TODO: LH - Apr '26 -> Clarify if this should start with attempt 1 or attempt 0
39
- @attempts_by_test_case_id[event.test_case.id] += 1
40
- @test_case_started_id_by_test_case_id[event.test_case.id] = @config.id_generator.new_id
41
- end
42
- end
43
- end
44
- end
45
- end