From bbc1c4691eb31e98641fa83b12339acacb658dea 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 ****************************************************** ``` Note that I also fixed a test name where "triggered" was spelled incorrectly. --- lib/deprecation_toolkit/behaviors/raise.rb | 4 ++++ test/deprecation_toolkit/behaviors/raise_test.rb | 6 +++++- .../deprecation_toolkit/behaviors/raise_test.yml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) 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") diff --git a/test/deprecations/deprecation_toolkit/behaviors/raise_test.yml b/test/deprecations/deprecation_toolkit/behaviors/raise_test.yml index 6e9b4d6..145be4b 100644 --- a/test/deprecations/deprecation_toolkit/behaviors/raise_test.yml +++ b/test/deprecations/deprecation_toolkit/behaviors/raise_test.yml @@ -5,7 +5,7 @@ test_.trigger_raises_a_DeprecationRemoved_error_when_deprecations_are_removed: test_.trigger_does_not_raise_when_deprecations_are_triggered_but_were_already_recorded: - 'DEPRECATION WARNING: Foo' - 'DEPRECATION WARNING: Bar' -test_.trigger_raises_a_DeprecationRemoved_when_less_deprecations_than_expected_are_triggerd_and_mismatches: +test_.trigger_raises_a_DeprecationRemoved_when_less_deprecations_than_expected_are_triggered_and_mismatches: - 'DEPRECATION WARNING: A' - 'DEPRECATION WARNING: B' test_.trigger_raises_a_DeprecationMismatch_when_same_number_of_deprecations_are_triggered_with_mismatches: