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 more deprecations #93

Merged
merged 10 commits into from
Nov 20, 2023
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activesupport_5.2.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

@activesupport_gem_requirement = "~> 5.2"
@activesupport_gem_requirement = "~> 5.2.0"

eval_gemfile "../Gemfile"
2 changes: 1 addition & 1 deletion gemfiles/activesupport_6.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

@activesupport_gem_requirement = "~> 6.0"
@activesupport_gem_requirement = "~> 6.0.0"

eval_gemfile "../Gemfile"
2 changes: 1 addition & 1 deletion gemfiles/activesupport_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

@activesupport_gem_requirement = "~> 6.1"
@activesupport_gem_requirement = "~> 6.1.0"

eval_gemfile "../Gemfile"
2 changes: 1 addition & 1 deletion gemfiles/activesupport_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

@activesupport_gem_requirement = "~> 7.0"
@activesupport_gem_requirement = "~> 7.0.0"

eval_gemfile "../Gemfile"
18 changes: 12 additions & 6 deletions lib/deprecation_toolkit/rspec_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions spec/deprecation_toolkit/behaviors/disabled_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::Disabled
Expand All @@ -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)
Expand Down
42 changes: 36 additions & 6 deletions spec/rspec/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,46 @@
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

it "should add `notify` behavior to the deprecations behavior list" do
with_rails_70_app do
behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify]

DeprecationToolkit::RSpecPlugin.before_suite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should move this to the with_rails_70_app helper actually? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having the test itself doing the exercise step if possible.

expect(ActiveSupport::Deprecation.behavior).to(include(behavior))
end
end

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))
DeprecationToolkit::RSpecPlugin.before_suite
ActiveSupport::Deprecation.behavior = behavior
expect(ActiveSupport::Deprecation.behavior).to(include(behavior))
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" do
it "doesn't remove previous deprecation behaviors with Rails.application.deprecators" do
behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:silence]
ActiveSupport::Deprecation.behavior = behavior
deprecator = Rails.application.deprecators.each.first

expect(ActiveSupport::Deprecation.behavior).to(include(behavior))
deprecator.behavior = behavior
expect(deprecator.behavior).to(include(behavior))
end
end
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
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"

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!
Expand Down
6 changes: 4 additions & 2 deletions test/deprecation_toolkit/behaviors/disabled_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module DeprecationToolkit
module Behaviors
class DisabledTest < ActiveSupport::TestCase
include TestDeprecator

setup do
@previous_configuration = Configuration.behavior
Configuration.behavior = Disabled
Expand All @@ -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
Expand Down
22 changes: 13 additions & 9 deletions test/minitest/deprecation_toolkit_plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions test/support/fake_rails.rb
Original file line number Diff line number Diff line change
@@ -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
29 changes: 6 additions & 23 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,11 @@
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
if ActiveSupport.respond_to?(:deprecator)
ActiveSupport.deprecator.behavior = :raise
else
ActiveSupport::Deprecation.behavior = :raise
end
ActiveSupport::TestCase.test_order = :random