Shopify / Shopify/deprecation_toolkit
How to deal with deprecations triggered on load?
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 538
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
Related to #20, but seemed different enough to put in a separate ticket.
I'm working on setting up this gem in our app and am liking it a lot, but I'm having trouble figuring out how to manage the deprecations that are triggered by class-level code execution. If files are autoloaded, those deprecations pop up unpredictably depending on which test happens to load the class first.
I'm curious how you manage these at Shopify, since surely you've run into this. I've tried setting config.eager_load = true in test, but that seems to cause the warning to completely vanish, which isn't what I want. Right now I'm just whitelisting them one by one in allowed_deprecations, which works okay but is awkward and time-consuming.
For example, here's a fairly normal invocation of a deprecated method as of Rails 7.1:
class MyJob < ApplicationJob
retry_on(StandardError, attempts: 25, wait: :exponentially_longer) do |job, _exception|
job.on_permanent_failure
end
...
end
And now running a handful of tests, the deprecation lands on whichever test first references that job:
Error:
MyTest#test_call:_does_thing_one:
DeprecationToolkit::Behaviors::DeprecationIntroduced: You have introduced new deprecations in the codebase. Fix or record them in order to discard this error.
You can record deprecations by adding the `--record-deprecations` flag when running your tests.
******* The following deprecations were added: *******
DEPRECATION WARNING: `wait: :exponentially_longer` will actually wait polynomially longer and is therefore deprecated. Prefer `wait: :polynomially_longer` to avoid confusion and keep the same behavior. (called from ...)
******************************************************
/usr/local/bundle/gems/deprecation_toolkit-2.2.4/lib/deprecation_toolkit/behaviors/raise.rb:17:in `trigger'
/usr/local/bundle/gems/deprecation_toolkit-2.2.4/lib/deprecation_toolkit/test_triggerer.rb:11:in `trigger_deprecation_toolkit_behavior'
/usr/local/bundle/gems/deprecation_toolkit-2.2.4/lib/deprecation_toolkit/minitest_hook.rb:8:in `trigger_deprecation_toolkit_behavior'
Error:
MyTest#test_call:_does_thing_two:
DeprecationToolkit::Behaviors::DeprecationRemoved: You have removed deprecations from the codebase. Thanks for being an awesome person.
The recorded deprecations needs to be updated to reflect your changes.
You can re-record deprecations by adding the `--record-deprecations` flag when running your tests.
****** The following deprecations were removed: ******
DEPRECATION WARNING: `wait: :exponentially_longer` will actually wait polynomially longer and is therefore deprecated. Prefer `wait: :polynomially_longer` to avoid confusion and keep the same behavior.
******************************************************
/usr/local/bundle/gems/deprecation_toolkit-2.2.4/lib/deprecation_toolkit/behaviors/raise.rb:17:in `trigger'
/usr/local/bundle/gems/deprecation_toolkit-2.2.4/lib/deprecation_toolkit/test_triggerer.rb:11:in `trigger_deprecation_toolkit_behavior'
/usr/local/bundle/gems/deprecation_toolkit-2.2.4/lib/deprecation_toolkit/minitest_hook.rb:8:in `trigger_deprecation_toolkit_behavior'
I did take advantage of #26 and have added this at the top of my test_helper to try to catch things as early as possible, but it doesn't seem perfect, and at any rate would not be able to record things caught outside of a test:
# test_helper.rb
require "deprecation_toolkit"
DeprecationToolkit.add_notify_behavior
DeprecationToolkit.attach_subscriber
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the load-time path around DeprecationToolkit.add_notify_behavior and attach_subscriber in test_helper, then inspect the reported test_triggerer.rb and minitest_hook.rb entry points. Compare this with the behavior described in issues #20 and #26. Done requires an agreed approach for detecting or recording deprecations triggered outside individual tests, but the issue does not define that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- developer-experience, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100