From e9b22a3063fd7d98bb405ca52c8215371400ecab Mon Sep 17 00:00:00 2001 From: Vincent Pretre Date: Wed, 24 Jun 2020 08:49:27 +0200 Subject: [PATCH 1/2] Add test describing issue #1433 --- .../formatter/query/hook_by_test_step_spec.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/cucumber/formatter/query/hook_by_test_step_spec.rb b/spec/cucumber/formatter/query/hook_by_test_step_spec.rb index 54f6707e34..e749bdb8cd 100644 --- a/spec/cucumber/formatter/query/hook_by_test_step_spec.rb +++ b/spec/cucumber/formatter/query/hook_by_test_step_spec.rb @@ -73,6 +73,26 @@ module Query end end end + + describe 'with AfterStep hooks' do + context '#pickle_step_id' do + define_feature <<-FEATURE + Feature: Banana party + + Scenario: Monkey eats banana + Given there are bananas + FEATURE + + define_steps do + AfterStep() {} + end + + it 'provides the ID of the AfterStepHook used to generate the Test::Step' do + test_case = @test_cases.first + expect(@formatter.hook_id(test_case.test_steps.last)).to eq(@hook_ids.first) + end + end + end end end end From 89544dfd5983967660d7876029c590b07bdb3085 Mon Sep 17 00:00:00 2001 From: Vincent Pretre Date: Wed, 24 Jun 2020 09:31:53 +0200 Subject: [PATCH 2/2] Emit missing event for AfterStep hook --- CHANGELOG.md | 2 +- lib/cucumber/runtime/step_hooks.rb | 7 +++++-- lib/cucumber/runtime/support_code.rb | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e4e6643ae..51e9a63ae6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo ### Fixed -* N/A +* `AfterStep` hook do not cause issue when running `message` formatter. [#1433](https://github.com/cucumber/cucumber-ruby/issues/1433) - [#1434](https://github.com/cucumber/cucumber-ruby/pull/1434) ## [4.0.1](https://github.com/cucumber/cucumber-ruby/compare/v4.0.0...v4.0.1) diff --git a/lib/cucumber/runtime/step_hooks.rb b/lib/cucumber/runtime/step_hooks.rb index 1759a6e8ee..91edcad9c7 100644 --- a/lib/cucumber/runtime/step_hooks.rb +++ b/lib/cucumber/runtime/step_hooks.rb @@ -3,9 +3,10 @@ module Cucumber class Runtime class StepHooks - def initialize(id_generator, hooks) + def initialize(id_generator, hooks, event_bus) @hooks = hooks @id_generator = id_generator + @event_bus = event_bus end def apply(test_steps) @@ -19,7 +20,9 @@ def apply(test_steps) def after_step_hooks(test_step) @hooks.map do |hook| action = ->(*args) { hook.invoke('AfterStep', [args, test_step]) } - Hooks.after_step_hook(@id_generator.new_id, test_step, hook.location, &action) + hook_step = Hooks.after_step_hook(@id_generator.new_id, test_step, hook.location, &action) + @event_bus.hook_test_step_created(hook_step, hook) + hook_step end end end diff --git a/lib/cucumber/runtime/support_code.rb b/lib/cucumber/runtime/support_code.rb index bf4a331b3e..20842b8cc7 100644 --- a/lib/cucumber/runtime/support_code.rb +++ b/lib/cucumber/runtime/support_code.rb @@ -104,7 +104,7 @@ def step_definitions def find_after_step_hooks(test_case) scenario = RunningTestCase.new(test_case) hooks = registry.hooks_for(:after_step, scenario) - StepHooks.new(@configuration.id_generator, hooks) + StepHooks.new(@configuration.id_generator, hooks, @configuration.event_bus) end def apply_before_hooks(test_case)