@@ -29,11 +29,24 @@ def warn(*messages)
29
29
30
30
# There are two forms of the `warn` method: one for class Kernel and one for instances of Kernel (i.e., every Object)
31
31
Object . prepend ( KernelWarnTracker )
32
- Kernel . singleton_class . prepend ( KernelWarnTracker )
33
32
34
- def self . track_rspec ( rspec_config , shitlist_path :, mode :, transform_message : nil )
33
+ # Ruby 2.2 and lower doesn't appear to allow overriding of Kernel.warn using `singleton_class.prepend`.
34
+ if Gem ::Version . new ( RUBY_VERSION ) >= Gem ::Version . new ( "2.3.0" )
35
+ Kernel . singleton_class . prepend ( KernelWarnTracker )
36
+ else
37
+ def Kernel . warn ( *args , &block )
38
+ Object . warn ( *args , &block )
39
+ end
40
+ end
41
+
42
+ def self . track_rspec ( rspec_config , opts = { } )
43
+ shitlist_path = opts [ :shitlist_path ]
44
+ mode = opts [ :mode ]
45
+ transform_message = opts [ :transform_message ]
35
46
deprecation_tracker = DeprecationTracker . new ( shitlist_path , transform_message )
36
- ActiveSupport ::Deprecation . behavior << -> ( message , _callstack , _deprecation_horizon , _gem_name ) { deprecation_tracker . add ( message ) }
47
+ if defined? ( ActiveSupport )
48
+ ActiveSupport ::Deprecation . behavior << -> ( message , _callstack , _deprecation_horizon , _gem_name ) { deprecation_tracker . add ( message ) }
49
+ end
37
50
KernelWarnTracker . callbacks << -> ( message ) { deprecation_tracker . add ( message ) }
38
51
39
52
rspec_config . around do |example |
@@ -86,7 +99,7 @@ def compare
86
99
end
87
100
88
101
if changed_buckets . length > 0
89
- message = <<~ MESSAGE . red
102
+ message = <<- MESSAGE . red
90
103
⚠️ Deprecation warnings have changed!
91
104
92
105
Code called by the following spec files is now generating different deprecation warnings:
@@ -119,7 +132,7 @@ def save
119
132
new_shitlist = create_temp_shitlist
120
133
FileUtils . cp ( new_shitlist . path , shitlist_path )
121
134
ensure
122
- new_shitlist & .delete
135
+ new_shitlist . delete if new_shitlist
123
136
end
124
137
125
138
def create_temp_shitlist
0 commit comments