Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record deprecations outside of rspec/minitest #102

Open
michaelbridge opened this issue Mar 27, 2024 · 1 comment
Open

Record deprecations outside of rspec/minitest #102

michaelbridge opened this issue Mar 27, 2024 · 1 comment

Comments

@michaelbridge
Copy link

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
Copy link
Member

You would need something like this for the setup:

DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
end
DeprecationToolkit.add_notify_behavior
DeprecationToolkit.attach_subscriber

and something like this to write the deprecations to the files:

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(self)

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.

deprecation_file = recorded_deprecations_path(test)
write(deprecation_file, test_name(test) => collector.deprecations_without_stacktrace)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants