From f97a44bb0a9228169387c57b7c5c935d5702bb23 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 21 Jan 2025 12:19:29 -0500 Subject: [PATCH] Make deprecator messaging clearer The deprecator messaging was confusing when outputting deprecations, especially if one was removed. The way this was written previously it would appear like the deprecator was looping - saying a deprecation was removed and then immediately showing the deprecation. To make the messaging clearer and to distinguish it from a deprecation that is being thrown, put copy around the deprecations. Before: ``` Minitest::UnexpectedError: 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. DEPRECATION WARNING: a deprecation warning ``` After: ``` Minitest::UnexpectedError: 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: a deprecation warning ****************************************************** ``` --- lib/deprecation_toolkit/behaviors/raise.rb | 4 ++++ test/deprecation_toolkit/behaviors/raise_test.rb | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/deprecation_toolkit/behaviors/raise.rb b/lib/deprecation_toolkit/behaviors/raise.rb index a12eff3..0e9dcd2 100644 --- a/lib/deprecation_toolkit/behaviors/raise.rb +++ b/lib/deprecation_toolkit/behaviors/raise.rb @@ -34,7 +34,9 @@ def initialize(current_deprecations, recorded_deprecations) You have introduced new deprecations in the codebase. Fix or record them in order to discard this error. #{record_message} + ******* The following deprecations were added: ******* #{introduced_deprecations.join("\n")} + ****************************************************** EOM super(message) @@ -57,7 +59,9 @@ def initialize(current_deprecations, recorded_deprecations) The recorded deprecations needs to be updated to reflect your changes. #{record_message} + ****** The following deprecations were removed: ****** #{removed_deprecations.join("\n")} + ****************************************************** EOM super(message) diff --git a/test/deprecation_toolkit/behaviors/raise_test.rb b/test/deprecation_toolkit/behaviors/raise_test.rb index 2446d37..5bcea5b 100644 --- a/test/deprecation_toolkit/behaviors/raise_test.rb +++ b/test/deprecation_toolkit/behaviors/raise_test.rb @@ -34,21 +34,25 @@ class RaiseTest < ActiveSupport::TestCase 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: Bar + ****************************************************** EOM deprecator.warn("Foo") end - test ".trigger raises a DeprecationRemoved when less deprecations than expected are triggerd and mismatches" do + test ".trigger raises a DeprecationRemoved when less deprecations than expected are triggered and mismatches" do @expected_exception_class = DeprecationRemoved @expected_exception_message = <<~EOM 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: A DEPRECATION WARNING: B + ****************************************************** EOM deprecator.warn("C")