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

Remove deprecations about ActiveSupport::Deprecation #90

Merged
merged 17 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ inherit_gem:

AllCops:
TargetRubyVersion: 2.6
SuggestExtensions: false
Exclude:
- gemfiles/vendor/**/*

Expand Down
18 changes: 15 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4.3)
activesupport (7.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.4)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
diff-lcs (1.5.0)
i18n (1.12.0)
drb (2.2.0)
ruby2_keywords
i18n (1.14.1)
concurrent-ruby (~> 1.0)
minitest (5.15.0)
minitest (5.20.0)
mutex_m (0.2.0)
parallel (1.21.0)
parser (3.1.1.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -52,6 +63,7 @@ GEM
rubocop-shopify (2.5.0)
rubocop (~> 1.25)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
Expand Down
9 changes: 8 additions & 1 deletion lib/deprecation_toolkit/warning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def handle_multipart(str)
def deprecation_triggered?(str)
DeprecationToolkit::Configuration.warnings_treated_as_deprecation.any? { |warning| warning =~ str }
end

def deprecator
@deprecator ||= ActiveSupport::Deprecation.new("next", "DeprecationToolkit::Warning").tap do |deprecator|
deprecator.behavior = :notify
DeprecationSubscriber.attach_to(:deprecation_toolkit_warning)
end
end
end
end

Expand All @@ -50,7 +57,7 @@ def warn(str)
return unless str

if DeprecationToolkit::Warning.deprecation_triggered?(str)
ActiveSupport::Deprecation.warn(str)
DeprecationToolkit::Warning.deprecator.warn(str)
else
super
end
Expand Down
20 changes: 11 additions & 9 deletions spec/deprecation_toolkit/behaviors/raise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "spec_helper"

RSpec.describe(DeprecationToolkit::Behaviors::Raise) do
include TestDeprecator

before do
@previous_configuration = DeprecationToolkit::Configuration.behavior
DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Raise
Expand All @@ -14,41 +16,41 @@

it ".trigger raises an DeprecationIntroduced error when deprecations are introduced" do |example|
expect do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationIntroduced))
end

it ".trigger raises a DeprecationRemoved error when deprecations are removed" do |example|
expect do
ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationRemoved))
end

it ".trigger raises a DeprecationRemoved when mismatched and less than expected" do |example|
expect do
ActiveSupport::Deprecation.warn("C")
deprecator.warn("C")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationRemoved))
end

it ".trigger raises a DeprecationMismatch when same number of deprecations are triggered with mismatches" do |example|
expect do
ActiveSupport::Deprecation.warn("A")
deprecator.warn("A")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationMismatch))
end

it ".trigger does not raise when deprecations are triggered but were already recorded" do |example|
expect do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end.not_to(raise_error)
Expand All @@ -59,7 +61,7 @@
DeprecationToolkit::Configuration.allowed_deprecations = [/John Doe/]

begin
ActiveSupport::Deprecation.warn("John Doe")
deprecator.warn("John Doe")
expect do
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end.not_to(raise_error)
Expand All @@ -75,7 +77,7 @@ def deprecation_caller
end

def deprecation_callee
ActiveSupport::Deprecation.warn("John Doe")
deprecator.warn("John Doe")
end
RUBY

Expand Down
14 changes: 8 additions & 6 deletions spec/deprecation_toolkit/behaviors/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "tmpdir"

RSpec.describe(DeprecationToolkit::Behaviors::Record) do
include TestDeprecator

before do
@previous_deprecation_path = DeprecationToolkit::Configuration.deprecation_path
@deprecation_path = Dir.mktmpdir
Expand All @@ -20,31 +22,31 @@

it ".trigger should record deprecations" do |example|
expect_deprecations_recorded("Foo", "Bar", example) do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end
end

it ".trigger re-record an existing deprecation file" do |example|
expect_deprecations_recorded("Foo", "Bar", example) do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end

expect_deprecations_recorded("Foo", example) do
ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end
end

it ".trigger removes the deprecation file when all deprecations were removed" do |example|
expect_deprecations_recorded("Foo", example) do
ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")

DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
require "deprecation_toolkit"
require "deprecation_toolkit/rspec_plugin"
require "active_support/all"
require_relative "../test/support/test_deprecator"

DeprecationToolkit::Configuration.test_runner = :rspec
DeprecationToolkit::Configuration.deprecation_path = "spec/deprecations"
ActiveSupport::Deprecation.behavior = :silence

RSpec.configure do |config|
# Disable RSpec exposing methods globally on `Module` and `main`
Expand Down
8 changes: 5 additions & 3 deletions test/deprecation_toolkit/behaviors/ci_record_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ class CIRecordHelperTest < ActiveSupport::TestCase
ci_output = +""
ci_output << "random stuff generated by CI, this should be filtered out by the Rake Task\n"

MyTest = Class.new(MiniTest::Test) do
MyTest = Class.new(::Minitest::Test) do
include TestDeprecator

def self.name
"MyTest"
end

def test_generate_deprecation
ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")
end

def test_generate_second_deprecation
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Bar")
end
end

Expand Down
26 changes: 15 additions & 11 deletions test/deprecation_toolkit/behaviors/raise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module DeprecationToolkit
module Behaviors
class RaiseTest < ActiveSupport::TestCase
include TestDeprecator

setup do
@previous_configuration = Configuration.behavior
Configuration.behavior = Raise
Expand All @@ -19,8 +21,8 @@ class RaiseTest < ActiveSupport::TestCase
@expected_exception_message =
/DEPRECATION\ WARNING\:\ Foo\ \(called\ from\ .*\nDEPRECATION\ WARNING\:\ Bar\ \(called from\ .*/

ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")
end

test ".trigger raises a DeprecationRemoved error when deprecations are removed" do
Expand All @@ -33,7 +35,7 @@ class RaiseTest < ActiveSupport::TestCase
DEPRECATION WARNING: Bar
EOM

ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")
end

test ".trigger raises a DeprecationRemoved when less deprecations than expected are triggerd and mismatches" do
Expand All @@ -47,7 +49,7 @@ class RaiseTest < ActiveSupport::TestCase
DEPRECATION WARNING: B
EOM

ActiveSupport::Deprecation.warn("C")
deprecator.warn("C")
end

test ".trigger raises a DeprecationMismatch when same number of deprecations are triggered with mismatches" do
Expand All @@ -64,13 +66,13 @@ class RaiseTest < ActiveSupport::TestCase
DEPRECATION WARNING: A
EOM

ActiveSupport::Deprecation.warn("A")
deprecator.warn("A")
end

test ".trigger does not raise when deprecations are triggered but were already recorded" do
assert_nothing_raised do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")
end
end

Expand All @@ -79,7 +81,7 @@ class RaiseTest < ActiveSupport::TestCase
Configuration.allowed_deprecations = [/John Doe/]

begin
ActiveSupport::Deprecation.warn("John Doe")
deprecator.warn("John Doe")
assert_nothing_raised { trigger_deprecation_toolkit_behavior }
ensure
Configuration.allowed_deprecations = @old_allowed_deprecations
Expand All @@ -93,7 +95,9 @@ def deprecation_caller
end

def deprecation_callee
ActiveSupport::Deprecation.warn("John Doe")
deprecator = ActiveSupport::Deprecation.new
deprecator.behavior = :notify
deprecator.warn("John Doe")
end
RUBY

Expand All @@ -112,8 +116,8 @@ def deprecation_callee

test ".trigger does not raise when test is flaky" do
assert_nothing_raised do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")
end
end

Expand Down
16 changes: 9 additions & 7 deletions test/deprecation_toolkit/behaviors/record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
module DeprecationToolkit
module Behaviors
class RecordTest < ActiveSupport::TestCase
include TestDeprecator

setup do
@previous_deprecation_path = Configuration.deprecation_path
@deprecation_path = Dir.mktmpdir
Expand All @@ -22,8 +24,8 @@ class RecordTest < ActiveSupport::TestCase

test ".trigger record deprecations" do
assert_deprecations_recorded("Foo", "Bar") do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")

trigger_deprecation_toolkit_behavior
end
Expand All @@ -35,7 +37,7 @@ class RecordTest < ActiveSupport::TestCase
end

assert_deprecations_recorded("Foo", to: "#{@deprecation_path}/prefix") do
ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")

trigger_deprecation_toolkit_behavior
end
Expand All @@ -55,22 +57,22 @@ class RecordTest < ActiveSupport::TestCase

test ".trigger re-record an existing deprecation file" do
assert_deprecations_recorded("Foo", "Bar") do
ActiveSupport::Deprecation.warn("Foo")
ActiveSupport::Deprecation.warn("Bar")
deprecator.warn("Foo")
deprecator.warn("Bar")

trigger_deprecation_toolkit_behavior
end

assert_deprecations_recorded("Foo") do
ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")

trigger_deprecation_toolkit_behavior
end
end

test ".trigger removes the deprecation file when all deprecations were removed" do
assert_deprecations_recorded("Foo") do
ActiveSupport::Deprecation.warn("Foo")
deprecator.warn("Foo")

trigger_deprecation_toolkit_behavior
end
Expand Down
6 changes: 4 additions & 2 deletions test/deprecation_toolkit/warning_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class WarningTest < ActiveSupport::TestCase
end

test "warn works as usual when no warnings are treated as deprecation" do
assert_nothing_raised do
warn "Test warn works correctly"
capture_io do
assert_nothing_raised do
warn "Test warn works correctly"
end
end
end

Expand Down
Loading