Skip to content

Commit 014a199

Browse files
committed
Merge remote-tracking branch 'origin/refactor/update_cck_conformance' into refactor/update_cck_conformance
2 parents 20a2a21 + d2a26a1 commit 014a199

6 files changed

Lines changed: 79 additions & 3 deletions

File tree

compatibility/cck_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
items_to_fix =
2626
%w[
27-
global-hooks
2827
global-hooks-afterall-error
2928
global-hooks-attachments
3029
global-hooks-beforeall-error

lib/cucumber/events.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def self.registry
3434
TestCaseStarted,
3535
TestCaseReady,
3636
TestRunFinished,
37+
TestRunHookFinished,
38+
TestRunHookStarted,
3739
TestRunStarted,
3840
TestStepCreated,
3941
TestStepFinished,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require 'cucumber/core/events'
4+
5+
module Cucumber
6+
module Events
7+
class TestRunHookFinished < Core::Event.new(:hook, :test_result)
8+
attr_reader :hook, :test_result
9+
end
10+
end
11+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require 'cucumber/core/events'
4+
5+
module Cucumber
6+
module Events
7+
class TestRunHookStarted < Core::Event.new(:hook)
8+
attr_reader :hook
9+
end
10+
end
11+
end

lib/cucumber/formatter/message_builder.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def initialize(config)
4242
config.on_event :test_case_started, &method(:on_test_case_started)
4343
config.on_event :test_run_finished, &method(:on_test_run_finished)
4444
config.on_event :test_run_started, &method(:on_test_run_started)
45+
config.on_event :test_run_hook_started, &method(:on_test_run_hook_started)
46+
config.on_event :test_run_hook_finished, &method(:on_test_run_hook_finished)
4547
# TODO: Handle TestStepCreated
4648
config.on_event :test_step_finished, &method(:on_test_step_finished)
4749
config.on_event :test_step_started, &method(:on_test_step_started)
@@ -296,6 +298,45 @@ def on_step_definition_registered(event)
296298
output_envelope(event.step_definition.to_envelope)
297299
end
298300

301+
def on_test_run_hook_started(event)
302+
@current_test_run_hook_started_id = @config.id_generator.new_id
303+
304+
message = Cucumber::Messages::Envelope.new(
305+
test_run_hook_started: Cucumber::Messages::TestRunHookStarted.new(
306+
id: @current_test_run_hook_started_id,
307+
hook_id: event.hook.id,
308+
test_run_started_id: @test_run_started.id,
309+
timestamp: time_to_timestamp(Time.now)
310+
)
311+
)
312+
313+
output_envelope(message)
314+
end
315+
316+
def on_test_run_hook_finished(event)
317+
result = event.test_result
318+
result_message = result.to_message
319+
320+
if result.failed?
321+
result_message = Cucumber::Messages::TestStepResult.new(
322+
status: result_message.status,
323+
duration: result_message.duration,
324+
message: create_error_message(result.exception),
325+
exception: create_exception_object(result, result.exception)
326+
)
327+
end
328+
329+
message = Cucumber::Messages::Envelope.new(
330+
test_run_hook_finished: Cucumber::Messages::TestRunHookFinished.new(
331+
test_run_hook_started_id: @current_test_run_hook_started_id,
332+
timestamp: time_to_timestamp(Time.now),
333+
result: result_message
334+
)
335+
)
336+
337+
output_envelope(message)
338+
end
339+
299340
def on_undefined_parameter_type(event)
300341
message = Cucumber::Messages::Envelope.new(
301342
undefined_parameter_type: Cucumber::Messages::UndefinedParameterType.new(

lib/cucumber/glue/registry_and_more.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ def install_plugin(configuration, registry)
148148

149149
def before_all
150150
hooks[:before_all].each do |hook|
151-
hook.invoke('BeforeAll', [])
151+
invoke_run_hook(hook, 'BeforeAll')
152152
end
153153
end
154154

155155
def after_all
156156
hooks[:after_all].each do |hook|
157-
hook.invoke('AfterAll', [])
157+
invoke_run_hook(hook, 'AfterAll')
158158
end
159159
end
160160

@@ -180,6 +180,18 @@ def create_expression(string_or_regexp)
180180

181181
private
182182

183+
def invoke_run_hook(hook, pseudo_method)
184+
@configuration.notify(:test_run_hook_started, hook)
185+
timer = Core::Test::Timer.new.start
186+
begin
187+
hook.invoke(pseudo_method, [])
188+
@configuration.notify(:test_run_hook_finished, hook, Core::Test::Result::Passed.new(timer.duration))
189+
rescue StandardError => e
190+
@configuration.notify(:test_run_hook_finished, hook, Core::Test::Result::Failed.new(timer.duration, e))
191+
raise
192+
end
193+
end
194+
183195
def parameter_type_envelope(parameter_type)
184196
# TODO: should this be moved to Cucumber::Expression::ParameterType#to_envelope ??
185197
# Note: that would mean that cucumber-expression would depend on cucumber-messages

0 commit comments

Comments
 (0)