Skip to content

Commit

Permalink
Make deprecator messaging clearer (#125)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eileencodes authored Jan 22, 2025
1 parent 91b5a3c commit 6be1a50
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/deprecation_toolkit/behaviors/raise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/deprecation_toolkit/behaviors/raise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6be1a50

Please sign in to comment.