@@ -17,46 +17,43 @@ def new_protected_method; "abc" end
17
17
def new_private_method ; "abc" end
18
18
alias_method :old_private_method , :new_private_method
19
19
end
20
+
21
+ @deprecator = ActiveSupport ::Deprecation . new
20
22
end
21
23
22
24
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 )
25
26
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
27
30
end
28
31
29
32
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 )
32
34
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
34
38
end
35
39
36
40
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 )
43
43
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
50
47
end
51
48
52
49
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 )
54
51
55
52
assert ( @klass . protected_method_defined? ( :old_protected_method ) )
56
53
end
57
54
58
55
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 )
60
57
61
58
assert ( @klass . private_method_defined? ( :old_private_method ) )
62
59
end
@@ -69,10 +66,11 @@ def old_method
69
66
"abc"
70
67
end
71
68
end
72
- ActiveSupport :: Deprecation . deprecate_methods ( mod , old_method : :new_method )
69
+ @deprecator . deprecate_methods ( mod , :old_method )
73
70
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
76
74
end
77
75
78
76
def test_deprecate_method_when_class_extends_module
@@ -81,10 +79,11 @@ def old_method
81
79
"abc"
82
80
end
83
81
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 )
86
84
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
89
88
end
90
89
end
0 commit comments