From 66ddd1870e9ffa9793cdd3665d8840a1e4777d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 14:52:51 +0100 Subject: [PATCH 01/10] Remove deprecated behavior from DisabledTest --- test/deprecation_toolkit/behaviors/disabled_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/deprecation_toolkit/behaviors/disabled_test.rb b/test/deprecation_toolkit/behaviors/disabled_test.rb index facaa11..855f715 100644 --- a/test/deprecation_toolkit/behaviors/disabled_test.rb +++ b/test/deprecation_toolkit/behaviors/disabled_test.rb @@ -5,6 +5,8 @@ module DeprecationToolkit module Behaviors class DisabledTest < ActiveSupport::TestCase + include TestDeprecator + setup do @previous_configuration = Configuration.behavior Configuration.behavior = Disabled @@ -16,8 +18,8 @@ class DisabledTest < ActiveSupport::TestCase test ".trigger noop any deprecations" do assert_nothing_raised do - ActiveSupport::Deprecation.warn("Foo") - ActiveSupport::Deprecation.warn("Bar") + deprecator.warn("Foo") + deprecator.warn("Bar") trigger_deprecation_toolkit_behavior end From 8fe1fd951fcc33cdffcb8ca91453773422783f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 14:53:26 +0100 Subject: [PATCH 02/10] Remove deprecated behavior from DeprecationToolkitPluginTest --- .../deprecation_toolkit_plugin_test.rb | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/minitest/deprecation_toolkit_plugin_test.rb b/test/minitest/deprecation_toolkit_plugin_test.rb index d1d5b81..b2dd635 100644 --- a/test/minitest/deprecation_toolkit_plugin_test.rb +++ b/test/minitest/deprecation_toolkit_plugin_test.rb @@ -119,17 +119,21 @@ def with_fake_application end test ".plugin_deprecation_toolkit_init doesn't init plugin when outside bundler context" do - notify_behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify] - old_bundle_gemfile = ENV["BUNDLE_GEMFILE"] - ENV.delete("BUNDLE_GEMFILE") + with_fake_application do + notify_behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify] + old_bundle_gemfile = ENV["BUNDLE_GEMFILE"] + ENV.delete("BUNDLE_GEMFILE") - ActiveSupport::Deprecation.behavior.delete(notify_behavior) - Minitest.plugin_deprecation_toolkit_init({}) + deprecator = Rails.application.deprecators.first + deprecator.behavior.delete(notify_behavior) - refute_includes(ActiveSupport::Deprecation.behavior, notify_behavior) - ensure - ENV["BUNDLE_GEMFILE"] = old_bundle_gemfile - ActiveSupport::Deprecation.behavior << notify_behavior + Minitest.plugin_deprecation_toolkit_init({}) + + refute_includes(deprecator.behavior, notify_behavior) + ensure + ENV["BUNDLE_GEMFILE"] = old_bundle_gemfile + deprecator.behavior << notify_behavior + end end end end From 29c60d3a78b21f5ffef8d827069c359b7e08de00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 14:55:43 +0100 Subject: [PATCH 03/10] Removed deprecated behavior from Disabled spec --- spec/deprecation_toolkit/behaviors/disabled_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/deprecation_toolkit/behaviors/disabled_spec.rb b/spec/deprecation_toolkit/behaviors/disabled_spec.rb index 702f33f..3f28443 100644 --- a/spec/deprecation_toolkit/behaviors/disabled_spec.rb +++ b/spec/deprecation_toolkit/behaviors/disabled_spec.rb @@ -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::Disabled @@ -14,8 +16,8 @@ it ".trigger noop any deprecations" 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) From c560d267d69a7896194fdd0148a5ce6e649c9c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 14:56:19 +0100 Subject: [PATCH 04/10] Extract fake Rails setup to use in specs --- spec/rspec/plugin_spec.rb | 30 ++++++++++++++++++++++-------- spec/spec_helper.rb | 1 + test/support/fake_rails.rb | 31 +++++++++++++++++++++++++++++++ test/test_helper.rb | 23 +---------------------- 4 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 test/support/fake_rails.rb diff --git a/spec/rspec/plugin_spec.rb b/spec/rspec/plugin_spec.rb index 98ab786..4cf4617 100644 --- a/spec/rspec/plugin_spec.rb +++ b/spec/rspec/plugin_spec.rb @@ -3,16 +3,30 @@ require "spec_helper" RSpec.describe(DeprecationToolkit::RSpecPlugin) do - it "should add `notify` behavior to the deprecations behavior list" do - behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify] + if ActiveSupport.gem_version < Gem::Version.new("7.1.0") + def with_rails_70_app + deprecators_before = Rails.application.method(:deprecators) + Rails.application.singleton_class.undef_method(:deprecators) + yield + ensure + Rails.application.singleton_class.define_method(:deprecators, &deprecators_before) + end - expect(ActiveSupport::Deprecation.behavior).to(include(behavior)) - end + it "should add `notify` behavior to the deprecations behavior list" do + with_rails_70_app do + behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify] + + expect(ActiveSupport::Deprecation.behavior).to(include(behavior)) + end + end - it "doesn't remove previous deprecation behaviors" do - behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:silence] - ActiveSupport::Deprecation.behavior = behavior + it "doesn't remove previous deprecation behaviors" do + with_rails_70_app do + behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:silence] - expect(ActiveSupport::Deprecation.behavior).to(include(behavior)) + ActiveSupport::Deprecation.behavior = behavior + expect(ActiveSupport::Deprecation.behavior).to(include(behavior)) + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 54e7128..f257ba7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,7 @@ require "deprecation_toolkit/rspec_plugin" require "active_support/all" require_relative "../test/support/test_deprecator" +require_relative "../test/support/fake_rails" DeprecationToolkit::Configuration.test_runner = :rspec DeprecationToolkit::Configuration.deprecation_path = "spec/deprecations" diff --git a/test/support/fake_rails.rb b/test/support/fake_rails.rb new file mode 100644 index 0000000..466d885 --- /dev/null +++ b/test/support/fake_rails.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# This is needed so that when we run the tests in this project, and the plugin is initialized by Minitest, we don't +# cause a deprecation warning by calling `ActiveSupport::Deprecation.behavior` and `.behavior=`. +module Rails + def self.application + Application + end + + module Application + def self.deprecators + @deprecators ||= DeprecatorSet.new + end + end + + class DeprecatorSet + def initialize + @deprecator = ActiveSupport::Deprecation.new + @deprecator.behavior = :raise + end + + def each + return to_enum unless block_given? + + yield @deprecator + end + + def behavior=(behavior) + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 4100d40..8bd1ecb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,28 +6,7 @@ require "minitest/autorun" require "active_support/all" require_relative "support/test_deprecator" +require_relative "support/fake_rails" ActiveSupport::Deprecation.behavior = :silence ActiveSupport::TestCase.test_order = :random - -# This is needed so that when we run the tests in this project, and the plugin is initialized by Minitest, we don't -# cause a deprecation warning by calling `ActiveSupport::Deprecation.behavior` and `.behavior=`. -module Rails - def self.application - Application - end - - module Application - def self.deprecators - DeprecatorSet - end - end - - module DeprecatorSet - def self.each - end - - def self.behavior=(behavior) - end - end -end From ae275bbc953d930f7341924ab9713f80afdcb9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 15:33:14 +0100 Subject: [PATCH 05/10] Make sure we're testing the correct versions Co-authored-by: Adrianna Chang --- gemfiles/activesupport_5.2.gemfile | 2 +- gemfiles/activesupport_6.0.gemfile | 2 +- gemfiles/activesupport_6.1.gemfile | 2 +- gemfiles/activesupport_7.0.gemfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gemfiles/activesupport_5.2.gemfile b/gemfiles/activesupport_5.2.gemfile index 43d25d2..b844ae7 100644 --- a/gemfiles/activesupport_5.2.gemfile +++ b/gemfiles/activesupport_5.2.gemfile @@ -1,5 +1,5 @@ # frozen_string_literal: true -@activesupport_gem_requirement = "~> 5.2" +@activesupport_gem_requirement = "~> 5.2.0" eval_gemfile "../Gemfile" diff --git a/gemfiles/activesupport_6.0.gemfile b/gemfiles/activesupport_6.0.gemfile index 968f823..540f830 100644 --- a/gemfiles/activesupport_6.0.gemfile +++ b/gemfiles/activesupport_6.0.gemfile @@ -1,5 +1,5 @@ # frozen_string_literal: true -@activesupport_gem_requirement = "~> 6.0" +@activesupport_gem_requirement = "~> 6.0.0" eval_gemfile "../Gemfile" diff --git a/gemfiles/activesupport_6.1.gemfile b/gemfiles/activesupport_6.1.gemfile index d022926..9152c74 100644 --- a/gemfiles/activesupport_6.1.gemfile +++ b/gemfiles/activesupport_6.1.gemfile @@ -1,5 +1,5 @@ # frozen_string_literal: true -@activesupport_gem_requirement = "~> 6.1" +@activesupport_gem_requirement = "~> 6.1.0" eval_gemfile "../Gemfile" diff --git a/gemfiles/activesupport_7.0.gemfile b/gemfiles/activesupport_7.0.gemfile index 0c22e7b..f222064 100644 --- a/gemfiles/activesupport_7.0.gemfile +++ b/gemfiles/activesupport_7.0.gemfile @@ -1,5 +1,5 @@ # frozen_string_literal: true -@activesupport_gem_requirement = "~> 7.0" +@activesupport_gem_requirement = "~> 7.0.0" eval_gemfile "../Gemfile" From 1d19a0ab2cc354b64983cfcf8847701342e51b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 15:34:16 +0100 Subject: [PATCH 06/10] Make the RSpec plugin behavior callable Co-authored-by: Adrianna Chang --- lib/deprecation_toolkit/rspec_plugin.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/deprecation_toolkit/rspec_plugin.rb b/lib/deprecation_toolkit/rspec_plugin.rb index 31a0ed1..d86f482 100644 --- a/lib/deprecation_toolkit/rspec_plugin.rb +++ b/lib/deprecation_toolkit/rspec_plugin.rb @@ -2,16 +2,22 @@ module DeprecationToolkit module RSpecPlugin + extend self + RSpec.configure do |config| config.before(:suite) do - case ENV["DEPRECATION_BEHAVIOR"] - when "r", "record", "record-deprecations" - DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record - end + RSpecPlugin.before_suite + end + end - DeprecationToolkit.add_notify_behavior - DeprecationToolkit.attach_subscriber + def before_suite + case ENV["DEPRECATION_BEHAVIOR"] + when "r", "record", "record-deprecations" + DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record end + + DeprecationToolkit.add_notify_behavior + DeprecationToolkit.attach_subscriber end end end From e8a5915ba3f714c0de779b55e6558b5afaa10534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 15:35:39 +0100 Subject: [PATCH 07/10] Call RSpec plugin Co-authored-by: Adrianna Chang --- spec/rspec/plugin_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/rspec/plugin_spec.rb b/spec/rspec/plugin_spec.rb index 4cf4617..5c06065 100644 --- a/spec/rspec/plugin_spec.rb +++ b/spec/rspec/plugin_spec.rb @@ -16,6 +16,7 @@ def with_rails_70_app with_rails_70_app do behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify] + DeprecationToolkit::RSpecPlugin.before_suite expect(ActiveSupport::Deprecation.behavior).to(include(behavior)) end end @@ -24,6 +25,7 @@ def with_rails_70_app with_rails_70_app do behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:silence] + DeprecationToolkit::RSpecPlugin.before_suite ActiveSupport::Deprecation.behavior = behavior expect(ActiveSupport::Deprecation.behavior).to(include(behavior)) end From db5a2da53f320dcc21c465c15e736bd1b8769223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 15:35:54 +0100 Subject: [PATCH 08/10] Also spec behavior under 7.1 Co-authored-by: Adrianna Chang --- spec/rspec/plugin_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/rspec/plugin_spec.rb b/spec/rspec/plugin_spec.rb index 5c06065..21c6b49 100644 --- a/spec/rspec/plugin_spec.rb +++ b/spec/rspec/plugin_spec.rb @@ -31,4 +31,18 @@ def with_rails_70_app end end end + + it "should add `notify` behavior to the deprecations behavior list with Rails.application.deprecators" do + behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify] + deprecator = Rails.application.deprecators.each.first + expect(deprecator.behavior).to(include(behavior)) + end + + it "doesn't remove previous deprecation behaviors with Rails.application.deprecators" do + behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:silence] + deprecator = Rails.application.deprecators.each.first + + deprecator.behavior = behavior + expect(deprecator.behavior).to(include(behavior)) + end end From 7903746d679205c56a1b5527179aac720e89877c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 14:57:19 +0100 Subject: [PATCH 09/10] Make the ActiveSupport deprecator raise to ensure no deprecated behavior This also removed the deprecated behavior of setting the behavior of the ActiveSupport::Deprecation singleton. Co-authored-by: Adrianna Chang --- spec/spec_helper.rb | 6 ++++++ test/test_helper.rb | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f257ba7..2f754c8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,12 @@ DeprecationToolkit::Configuration.test_runner = :rspec DeprecationToolkit::Configuration.deprecation_path = "spec/deprecations" +if ActiveSupport.respond_to?(:deprecator) + ActiveSupport.deprecator.behavior = :raise +else + ActiveSupport::Deprecation.behavior = :raise +end + RSpec.configure do |config| # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bd1ecb..29ee9af 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,5 +8,9 @@ require_relative "support/test_deprecator" require_relative "support/fake_rails" -ActiveSupport::Deprecation.behavior = :silence +if ActiveSupport.respond_to?(:deprecator) + ActiveSupport.deprecator.behavior = :raise +else + ActiveSupport::Deprecation.behavior = :raise +end ActiveSupport::TestCase.test_order = :random From 0a4dca665e262d5a2c99da07c26b9e4dcd571d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Fri, 17 Nov 2023 15:59:00 +0100 Subject: [PATCH 10/10] Test on 7.1 --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdf37b9..ff616c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,13 @@ jobs: name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }} strategy: matrix: - gemfile: [gemfiles/activesupport_5.2.gemfile, gemfiles/activesupport_6.0.gemfile, gemfiles/activesupport_6.1.gemfile, gemfiles/activesupport_7.0.gemfile, gemfiles/activesupport_edge.gemfile] + gemfile: + - Gemfile + - gemfiles/activesupport_5.2.gemfile + - gemfiles/activesupport_6.0.gemfile + - gemfiles/activesupport_6.1.gemfile + - gemfiles/activesupport_7.0.gemfile + - gemfiles/activesupport_edge.gemfile ruby: ["2.7", "3.0", "3.1", "3.2"] exclude: # Active Support requires Ruby >= 2.7 as of 7.0