@@ -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 (
0 commit comments