Skip to content

Commit 8354c3a

Browse files
Merge pull request rails#46107 from jonathanhefner/deprecation-tests-use-explicit-deprecator-pt4
Use explicit deprecator in wrappers tests
2 parents 32af4cd + 4fdcd31 commit 8354c3a

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

activesupport/test/deprecation/method_wrappers_test.rb

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,43 @@ def new_protected_method; "abc" end
1717
def new_private_method; "abc" end
1818
alias_method :old_private_method, :new_private_method
1919
end
20+
21+
@deprecator = ActiveSupport::Deprecation.new
2022
end
2123

2224
def test_deprecate_methods_without_alternate_method
23-
warning = /old_method is deprecated and will be removed from Rails \d.\d./
24-
ActiveSupport::Deprecation.deprecate_methods(@klass, :old_method)
25+
@deprecator.deprecate_methods(@klass, :old_method)
2526

26-
assert_deprecated(warning) { assert_equal "abc", @klass.new.old_method }
27+
assert_deprecated("old_method", @deprecator) do
28+
assert_equal @klass.new.new_method, @klass.new.old_method
29+
end
2730
end
2831

2932
def test_deprecate_methods_warning_default
30-
warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/
31-
ActiveSupport::Deprecation.deprecate_methods(@klass, old_method: :new_method)
33+
@deprecator.deprecate_methods(@klass, old_method: :new_method)
3234

33-
assert_deprecated(warning) { assert_equal "abc", @klass.new.old_method }
35+
assert_deprecated(/old_method .* \(use new_method instead\)/, @deprecator) do
36+
assert_equal @klass.new.new_method, @klass.new.old_method
37+
end
3438
end
3539

3640
def test_deprecate_methods_warning_with_optional_deprecator
37-
warning = /old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/
38-
deprecator = ActiveSupport::Deprecation.new("next-release", "MyGem")
39-
ActiveSupport::Deprecation.deprecate_methods(@klass, old_method: :new_method, deprecator: deprecator)
40-
41-
assert_deprecated(warning, deprecator) { assert_equal "abc", @klass.new.old_method }
42-
end
41+
@deprecator = ActiveSupport::Deprecation.new("next-release", "MyGem")
42+
ActiveSupport::Deprecation.deprecate_methods(@klass, :old_method, deprecator: @deprecator)
4343

44-
def test_deprecate_methods_warning_when_deprecated_with_custom_deprecator
45-
warning = /old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/
46-
deprecator = ActiveSupport::Deprecation.new("next-release", "MyGem")
47-
deprecator.deprecate_methods(@klass, old_method: :new_method)
48-
49-
assert_deprecated(warning, deprecator) { assert_equal "abc", @klass.new.old_method }
44+
assert_deprecated(/old_method .* MyGem next-release/, @deprecator) do
45+
assert_equal @klass.new.new_method, @klass.new.old_method
46+
end
5047
end
5148

5249
def test_deprecate_methods_protected_method
53-
ActiveSupport::Deprecation.deprecate_methods(@klass, old_protected_method: :new_protected_method)
50+
@deprecator.deprecate_methods(@klass, old_protected_method: :new_protected_method)
5451

5552
assert(@klass.protected_method_defined?(:old_protected_method))
5653
end
5754

5855
def test_deprecate_methods_private_method
59-
ActiveSupport::Deprecation.deprecate_methods(@klass, old_private_method: :new_private_method)
56+
@deprecator.deprecate_methods(@klass, old_private_method: :new_private_method)
6057

6158
assert(@klass.private_method_defined?(:old_private_method))
6259
end
@@ -69,10 +66,11 @@ def old_method
6966
"abc"
7067
end
7168
end
72-
ActiveSupport::Deprecation.deprecate_methods(mod, old_method: :new_method)
69+
@deprecator.deprecate_methods(mod, :old_method)
7370

74-
warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/
75-
assert_deprecated(warning) { assert_equal "abc", mod.old_method }
71+
assert_deprecated("old_method", @deprecator) do
72+
assert_equal "abc", mod.old_method
73+
end
7674
end
7775

7876
def test_deprecate_method_when_class_extends_module
@@ -81,10 +79,11 @@ def old_method
8179
"abc"
8280
end
8381
end
84-
@klass.extend mod
85-
ActiveSupport::Deprecation.deprecate_methods(mod, old_method: :new_method)
82+
klass = Class.new { extend mod }
83+
@deprecator.deprecate_methods(mod, :old_method)
8684

87-
warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/
88-
assert_deprecated(warning) { assert_equal "abc", @klass.old_method }
85+
assert_deprecated("old_method", @deprecator) do
86+
assert_equal "abc", klass.old_method
87+
end
8988
end
9089
end

activesupport/test/deprecation/proxy_wrappers_test.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def waffle?
1313
end
1414
end
1515

16+
def setup
17+
@deprecator = ActiveSupport::Deprecation.new
18+
end
19+
1620
def test_deprecated_object_proxy_doesnt_wrap_falsy_objects
1721
proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message")
1822
assert_not proxy
@@ -29,31 +33,31 @@ def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects
2933
end
3034

3135
def test_including_proxy_module
32-
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name)
36+
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name, @deprecator)
3337
klass = Class.new
34-
assert_deprecated do
38+
assert_deprecated("OldWaffleModule", @deprecator) do
3539
klass.include proxy
3640
end
3741
assert klass.new.waffle?
3842
end
3943

4044
def test_prepending_proxy_module
41-
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name)
45+
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name, @deprecator)
4246
klass = Class.new do
4347
def waffle?
4448
false
4549
end
4650
end
47-
assert_deprecated do
51+
assert_deprecated("OldWaffleModule", @deprecator) do
4852
klass.prepend proxy
4953
end
5054
assert klass.new.waffle?
5155
end
5256

5357
def test_extending_proxy_module
54-
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name)
58+
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name, @deprecator)
5559
obj = Object.new
56-
assert_deprecated do
60+
assert_deprecated("OldWaffleModule", @deprecator) do
5761
obj.extend proxy
5862
end
5963
assert obj.waffle?

0 commit comments

Comments
 (0)