deprecation_toolkit icon indicating copy to clipboard operation
deprecation_toolkit copied to clipboard

Record deprecations outside of rspec/minitest

Open michaelbridge opened this issue 1 year ago • 1 comments

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)

michaelbridge avatar Mar 27 '24 21:03 michaelbridge

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:

  • ReadWriteHelper#test_name(object), ReadWriteHelper#test_location(object) and ReadWriteHelper#recorded_deprecations_path(object) should work to give a path and name to be able to store deprecations for the object
  • ReadWriteHelper#read(object) to load the previously written deprecations (technically we might just ignore that, but you will need to copy and change some of the logic of TestTriggerer to cause the deprecations to be written while not necessitating to read them.

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.

etiennebarrie avatar Mar 28 '24 14:03 etiennebarrie