Shopify / deprecation_toolkit

⚒Eliminate deprecations from your codebase ⚒
MIT License
466 stars 40 forks source link

Record deprecations outside of rspec/minitest #102

Open michaelbridge opened 6 months ago

michaelbridge commented 6 months ago

For apps with less than 100% test coverage, is there any means of recording deprecations while running the app normally (i.e., in local development or a staging environment)? I've added the following early in the application's initialization, but this doesn't have the intended effect:

DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
DeprecationToolkit.send(:initialize)
etiennebarrie commented 6 months ago

You would need something like this for the setup: https://github.com/Shopify/deprecation_toolkit/blob/49818d43fc2e58740495267ee3fcc1ac40f4d881/lib/minitest/deprecation_toolkit_plugin.rb#L18-L22

and something like this to write the deprecations to the files: https://github.com/Shopify/deprecation_toolkit/blob/49818d43fc2e58740495267ee3fcc1ac40f4d881/lib/deprecation_toolkit/minitest_hook.rb#L8

The issue is that TestTriggerer (technically ReadWriteHelper) really expects a test (for minitest) or an example (for RSpec) to be able to generate the path for the collected deprecations.

But you might just be able to pass another object, but that object should pass a few requirements:

https://github.com/Shopify/deprecation_toolkit/blob/49818d43fc2e58740495267ee3fcc1ac40f4d881/lib/deprecation_toolkit/behaviors/record.rb#L10-L12

I feel like it could be interesting to be able to use on a controller (and have the controller name as the path, and the action as the "test name", i.e. the key in the recorded deprecations YAML), or a job (for jobs the test name makes less sense, it might just be perform all the time).

By providing a Proc for deprecation_path you should be able to handle those there.

test_name is going to be a bit harder because your object needs to answer to name, but maybe test_runner could support more than :rspec and :minitest.

If you manage to get it to work, it could be an interesting feature, keeping the deprecation collection logic while changing the "unit of work" (right now it's only collecting for test/example, we could add collecting for job/controller and support development).


But to be frank, the easiest way might be to write controller tests and use them to collect deprecations. This will also help you to make changes without breaking the app.