-
Notifications
You must be signed in to change notification settings - Fork 36
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