From b126fc89ac67a0f1cbd6c7366313566cb6a39c10 Mon Sep 17 00:00:00 2001 From: Luke Hill <20105237+luke-hill@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:05:21 +0000 Subject: [PATCH] bugfix: Handle Cucumber-Wire issue when parameter type cannot be specified on Envelope (#1746) * Handle NME from cucumber-wire - When step match argument cannot detect the parameter type name, return `nil` and then have the optional param fed as `nil` - When there is no parameter type (Because of legacy system), then return `nil` and have the optional param fed as `nil` * Add changelog --- CHANGELOG.md | 3 +++ lib/cucumber/formatter/message_builder.rb | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 302921dab..4346791ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo All logic contained in [compatibility](./compatibility) ([luke-hill](https://github.com/luke-hill)) ### Fixed +- Fix a situation whereby the step definition message will omit the parameter-type name when it cannot be inferred + (This fixes an issue in cucumber-wire when passing legacy steps down the wire) + ([#1746](https://github.com/cucumber/cucumber-ruby/pull/1746) [luke-hill](https://github.com/luke-hill)) ### Removed diff --git a/lib/cucumber/formatter/message_builder.rb b/lib/cucumber/formatter/message_builder.rb index e834b46b6..aebec612d 100644 --- a/lib/cucumber/formatter/message_builder.rb +++ b/lib/cucumber/formatter/message_builder.rb @@ -132,7 +132,7 @@ def step_match_arguments(step) @step_definitions_by_test_step.step_match_arguments(step).map do |argument| Cucumber::Messages::StepMatchArgument.new( group: argument_group_to_message(argument.group), - parameter_type_name: argument.parameter_type.name + parameter_type_name: parameter_type_name(argument) ) end end @@ -145,6 +145,10 @@ def argument_group_to_message(group) ) end + def parameter_type_name(step_match_argument) + step_match_argument.parameter_type&.name if step_match_argument.respond_to?(:parameter_type) + end + def on_test_run_started(*) message = Cucumber::Messages::Envelope.new( test_run_started: Cucumber::Messages::TestRunStarted.new(