Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error backtrace formatting on Ruby 3.4+ #1771

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

orien
Copy link
Contributor

@orien orien commented Dec 27, 2024

Description

Context

Cucumber performs filtering and formatting on error backtraces before displaying them in terminal output.

When running on Ruby 3.4, the backtrace filtering and formatting is not working. This is defect is caused by the new backtrace format introduced in Ruby 3.4.

See:

Change

Update the Cucumber::Glue::InvokeInWorld and Cucumber::Formatter::BacktraceFilter classes to support both styles of backtraces.

Fixes #1770

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

Your PR is ready for review once the following checklist is
complete. You can also add some checks if you want to.

  • Tests have been added for any changes to behaviour of the code
  • New and existing tests are passing locally and on CI
  • bundle exec rubocop reports no offenses
  • RDoc comments have been updated
  • CHANGELOG.md has been updated

.rubocop_todo.yml Outdated Show resolved Hide resolved
compatibility/cck_spec.rb Outdated Show resolved Hide resolved
@io.print options.inspect
@io.print options.to_json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Ruby 3.4 the Hash#inspect method produces a different format:

Ruby 3.4:

irb:001> { a: 1 }.inspect
=> "{a: 1}"
irb:002> { 'a' => 1 }.inspect
=> "{\"a\" => 1}"
irb:003> { 2 => 1 }.inspect
=> "{2 => 1}"

Ruby 3.3

irb:001> { a: 1 }.inspect
=> "{:a=>1}"
irb:002> { 'a' => 1 }.inspect
=> "{\"a\"=>1}"
irb:003> { 2 => 1 }.inspect
=> "{2=>1}"

Let's change the test to use to_json instead of inspect. This way the test expectations will be consistent across all versions of Ruby in the CI build matrix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find. I know this is the issue mainly in the main branch with regards to errors, nice that to_json gives us a quick fix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unresolving this so we know to look here for documentation purposes as/when a v10 is cut.

For now as part of this PR can you add some notes here: https://github.com/cucumber/cucumber-ruby/blob/main/upgrading_notes/10.0.0.md - if you are confident in doing so. Or if you'd prefer I can do it once this PR is merged. I'm flexible.

Copy link
Contributor Author

@orien orien Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you're referring to specifically. This is a test/doc file. The changes here shouldn't affect downstream users.

@orien orien marked this pull request as ready for review December 27, 2024 13:03
@orien orien changed the title Accomodate the Ruby 3.4+ backtrace display format Fix error backtrace formatting on Ruby 3.4+ Dec 27, 2024
@orien orien force-pushed the accomodate-ruby-3.4-backtraces branch 2 times, most recently from 7559a86 to 92684f6 Compare December 27, 2024 13:28
@voxik
Copy link
Contributor

voxik commented Jan 3, 2025

Trying these fixes to make this cucumber-wire test pass. Unfortunately without success. Is it something what could be fixed on Cucumber side? Or does the cucumber-wire need medicine like this:

diff --git a/features/handle_unexpected_response.feature b/features/handle_unexpected_response.feature
index 2d7747e..4e0aa8c 100644
--- a/features/handle_unexpected_response.feature
+++ b/features/handle_unexpected_response.feature
@@ -25,7 +27,7 @@ Feature: Handle unexpected response
       | ["begin_scenario"]                                   | ["yikes"]                           |
       | ["step_matches",{"name_to_match":"we're all wired"}] | ["success",[{"id":"1", "args":[]}]] |
     When I run `cucumber -f pretty`
-    Then the output should contain:
+    Then the output should match:
       """
-      undefined method `handle_yikes'
+      undefined method [`']handle_yikes'
       """

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially reviewed, probably won't have time this week. But this is near the top of my list.

Great work finding a good replacement!

@@ -87,16 +92,15 @@ module Glue

define_steps do
When('{word} {word} {word}') do |subject, verb, complement|
log "subject: #{subject}", "verb: #{verb}", "complement: #{complement}", subject: subject, verb: verb, complement: complement
log "subject: #{subject}", "verb: #{verb}", "complement: #{complement}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to be hard-coded. Aruba steps are designed to showcase simple examples and this has 3 parameter types for "I have no idea what reason...." So if this just becomes When('monkey eats banana') then we can make the logger step also hard coded and the test showcasing that the logger having 3 items gets translated will be a bit easier to understand

Notwithstanding that, I'm not sure I agree that "is" what happens though. So I'll probably need to dig into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 4740677.

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully reviewed this PR now. If you can respond to the points we can look to get this merged in soon and included in v10.

You'll also likely need to do some form of rebase. But it might be worth waiting as I'm doing a few derpy things in main currently.

lib/cucumber/formatter/backtrace_filter.rb Show resolved Hide resolved
lib/cucumber/glue/invoke_in_world.rb Show resolved Hide resolved
spec/cucumber/glue/proto_world_spec.rb Outdated Show resolved Hide resolved
expect(@out.string).to include '{:a=>1, :b=>2, :c=>3}'
it 'attached the string version on the object' do
expected_string = '<test-object>'
expect(@out.string).to include expected_string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line and wrap expected string in ()

spec/cucumber/glue/proto_world_spec.rb Show resolved Hide resolved
@orien orien force-pushed the accomodate-ruby-3.4-backtraces branch from f0ea48a to 645a442 Compare January 13, 2025 21:20
@orien orien force-pushed the accomodate-ruby-3.4-backtraces branch from 645a442 to 83683d5 Compare January 13, 2025 21:39
@orien
Copy link
Contributor Author

orien commented Jan 13, 2025

Fully reviewed this PR now. If you can respond to the points we can look to get this merged in soon and included in v10.

You'll also likely need to do some form of rebase. But it might be worth waiting as I'm doing a few derpy things in main currently.

Thanks @luke-hill. I think I've addressed everything and rebased the branch against main. Please let me know if/when I need to rebase again, if you're still working for v10.

@orien orien force-pushed the accomodate-ruby-3.4-backtraces branch from 83683d5 to 9620b48 Compare January 13, 2025 21:58
@orien orien force-pushed the accomodate-ruby-3.4-backtraces branch from 9620b48 to 039d006 Compare January 13, 2025 22:25
Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3/6 files are marked as good from me, couple of minor things to fix - I'll leave the note up for the doc updates as I still haven't got round to that yet. I will soon though as I've merged my chunky v10 diff.

lib/cucumber/formatter/backtrace_filter.rb Show resolved Hide resolved
lib/cucumber/glue/invoke_in_world.rb Show resolved Hide resolved
@luke-hill
Copy link
Contributor

For now @orien this is in a decent spot. So you can rest up for a while now as there's not much to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rspec testsuite error with ruby3.4.0dev
3 participants