Skip to content

Commit 1ff4596

Browse files
authored
Bugfix: Message Builder for Error Messages on testStepFinished (#1790)
* Add stack trace * Bugfixes. Ensure casing of stack-trace property and fix stringlike nature of it * Tidy up legacy error message method # * Add changelog * Bump CCK to v19 to ensure compatibility with latest issues * Remove superfluous step definitions in attachments * Tidy up message element to use a heredoc
1 parent 2cf3a61 commit 1ff4596

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
99
Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) for more info on how to contribute to Cucumber.
1010

1111
## [Unreleased]
12+
### Changed
13+
- Updated `cucumber-compatibility-kit` to v19
14+
15+
### Fixed
16+
- Fixed an issue where the html-formatter wasn't respecting the new structure for `StackTrace` cucumber messages ([#1790](https://github.com/cucumber/cucumber-ruby/pull/1790) [luke-hill](https://github.com/luke-hill))
1217

1318
## [10.0.0] - 2025-06-11
1419
### Changed

compatibility/features/attachments/attachments_steps.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ def cck_asset_path
2525
attach(data, media_type)
2626
end
2727

28-
# To be removed in CCK v19 alongside removing duplicate scenarios: https://github.com/cucumber/compatibility-kit/pull/127
29-
When('a JPEG image is attached') do
30-
attach(File.open("#{cck_asset_path}/cucumber.jpeg"), 'image/jpeg')
31-
end
32-
33-
# To be removed in CCK v19 alongside removing duplicate scenarios: https://github.com/cucumber/compatibility-kit/pull/127
34-
When('a PNG image is attached') do
35-
attach(File.open("#{cck_asset_path}/cucumber.png"), 'image/png')
36-
end
37-
3828
When('a PDF document is attached and renamed') do
3929
attach(File.open("#{cck_asset_path}/document.pdf"), 'application/pdf', 'renamed.pdf')
4030
end

cucumber.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
3535
s.add_dependency 'multi_test', '~> 1.1'
3636
s.add_dependency 'sys-uname', '~> 1.3'
3737

38-
s.add_development_dependency 'cucumber-compatibility-kit', '~> 18.0'
38+
s.add_development_dependency 'cucumber-compatibility-kit', '~> 19.0'
3939
# Only needed whilst we are testing the formatters. Can be removed once we remove tests for those
4040
s.add_development_dependency 'nokogiri', '~> 1.15'
4141
s.add_development_dependency 'rake', '~> 13.2'

lib/cucumber/formatter/message_builder.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ def on_test_step_started(event)
198198

199199
def on_test_step_finished(event)
200200
test_case = @test_case_by_step_id[event.test_step.id]
201-
result = event
202-
.result
203-
.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
201+
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
204202

205203
result_message = result.to_message
206204
if result.failed? || result.pending?
@@ -227,14 +225,20 @@ def on_test_step_finished(event)
227225
end
228226

229227
def create_error_message(message_element)
230-
message = "#{message_element.message} (#{message_element.class})"
231-
([message] + message_element.backtrace).join("\n")
228+
<<~ERROR_MESSAGE
229+
#{message_element.message} (#{message_element.class})
230+
#{message_element.backtrace}
231+
ERROR_MESSAGE
232232
end
233233

234234
def create_exception_object(result, message_element)
235235
return unless result.failed?
236236

237-
Cucumber::Messages::Exception.from_h({ type: message_element.class, message: message_element.message })
237+
Cucumber::Messages::Exception.new(
238+
type: message_element.class,
239+
message: message_element.message,
240+
stack_trace: message_element.backtrace.join("\n")
241+
)
238242
end
239243

240244
def on_test_case_finished(event)

0 commit comments

Comments
 (0)