ApprovalTests.Ruby icon indicating copy to clipboard operation
ApprovalTests.Ruby copied to clipboard

^ r make tests pass on all current Ruby versions

Open geeksam opened this issue 10 months ago • 2 comments

Description

Ruby 3.4 changed the behavior of Hash#inspect (bug 20433).

Because the Approvals::Writers::ArrayWriter and Approvals::Writers::HashWriter use #inspect to serialize the contents of arrays and hashes, this made it impossible to use a single fixture to verify their behavior on all current versions of Ruby.

The solution

I duplicated the tests for the behavior and added a [slightly ugly] conditional to the test suite to skip whichever version should NOT apply under the version of Ruby being used to execute the tests.

NOTE: because I will absolutely forget about this, I also added a "time bomb" to those tests that will begin failing after Ruby 3.3's official end-of-life date, and some comments about how to restore the code to its simpler state.

Summary by Sourcery

Update test suite to handle changes in Ruby 3.4's Hash#inspect behavior by adding version-specific test contexts

Bug Fixes:

  • Modify test suite to support different Hash#inspect behaviors across Ruby versions

Tests:

  • Add conditional test contexts to handle Ruby version-specific test variations
  • Implement a 'time bomb' to remind future maintainers to clean up version-specific test code

Chores:

  • Add version checking logic to test suite to manage compatibility across Ruby versions

geeksam avatar Mar 28 '25 17:03 geeksam

Reviewer's Guide by Sourcery

This pull request addresses a change in Hash#inspect behavior introduced in Ruby 3.4 that affected the Approvals::Writers::ArrayWriter and Approvals::Writers::HashWriter. To ensure tests pass on all current Ruby versions, the test suite was modified to conditionally skip tests based on the Ruby version. A time bomb was added to remind developers to remove the conditional logic after Ruby 3.3's end-of-life.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added conditional logic to the test suite to skip tests based on the Ruby version, accommodating changes in Hash#inspect behavior in Ruby 3.4.
  • Introduced a context block to conditionally execute tests based on the Ruby version.
  • Added before blocks to skip tests for Ruby versions where they are not applicable.
  • Duplicated tests for array and hash writers to support different Ruby versions.
  • Included a 'time bomb' that will cause tests to fail after Ruby 3.3's end-of-life date, along with instructions on how to revert the changes.
spec/approvals_spec.rb
Added new approval fixtures to accommodate changes in Hash#inspect behavior in Ruby 3.4.
  • Added a new approval fixture for the array writer.
  • Added a new approval fixture for the hash writer.
spec/fixtures/approvals/approvals_supports_excluded_keys_option_while_were_still_supporting_ruby__34_in_ruby_versions_34_and_beyond_supports_the_array_writer.approved.txt
spec/fixtures/approvals/approvals_supports_excluded_keys_option_while_were_still_supporting_ruby__34_in_ruby_versions_34_and_beyond_supports_the_hash_writer.approved.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Mar 28 '25 17:03 sourcery-ai[bot]

Wow, that AI bot is annoying.

geeksam avatar Mar 28 '25 17:03 geeksam

we fixed this a better way :)

geeksam avatar Apr 23 '25 23:04 geeksam