Skip to content

Commit 53a87ba

Browse files
committed
Merge branch 'fixes/ruby-2-2-syntax-error'
2 parents 38d89f0 + 4a0a70a commit 53a87ba

File tree

5 files changed

+67
-50
lines changed

5 files changed

+67
-50
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
sudo: false
22
language: ruby
33
rvm:
4+
- 2.2.10
45
- 2.3.3
56
before_install: gem install bundler -v 1.16.1

exe/bundle_report

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ at_exit do
99

1010
options = {}
1111
option_parser = OptionParser.new do |opts|
12-
opts.banner = <<~EOS
12+
opts.banner = <<-EOS
1313
Usage: #{$0} [report-type] [options]
1414
1515
report-type There are two report types available: `outdated` and `compatibility`

exe/deprecations

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ require "colorize"
44
require "optparse"
55
require "set"
66

7-
def run_tests(deprecation_warnings, tracker_mode:, next_mode:)
7+
def run_tests(deprecation_warnings, opts = {})
8+
tracker_mode = opts[:tracker_mode]
9+
next_mode = opts[:next_mode]
810
rspec_command = if next_mode
911
"bin/next rspec"
1012
else
@@ -16,7 +18,8 @@ def run_tests(deprecation_warnings, tracker_mode:, next_mode:)
1618
exec command
1719
end
1820

19-
def print_info(deprecation_warnings, verbose: false)
21+
def print_info(deprecation_warnings, opts = {})
22+
verbose = !!opts[:verbose]
2023
frequency_by_message = deprecation_warnings.each_with_object({}) do |(test_file, messages), hash|
2124
messages.each do |message|
2225
hash[message] ||= { test_files: Set.new, occurrences: 0 }
@@ -36,7 +39,7 @@ end
3639

3740
options = {}
3841
option_parser = OptionParser.new do |opts|
39-
opts.banner = <<~MESSAGE
42+
opts.banner = <<-MESSAGE
4043
Usage: #{__FILE__.to_s} [options] [mode]
4144
4245
Parses the deprecation warning shitlist and show info or run tests.

lib/deprecation_tracker.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,24 @@ def warn(*messages)
2929

3030
# There are two forms of the `warn` method: one for class Kernel and one for instances of Kernel (i.e., every Object)
3131
Object.prepend(KernelWarnTracker)
32-
Kernel.singleton_class.prepend(KernelWarnTracker)
3332

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]
3546
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
3750
KernelWarnTracker.callbacks << -> (message) { deprecation_tracker.add(message) }
3851

3952
rspec_config.around do |example|
@@ -86,7 +99,7 @@ def compare
8699
end
87100

88101
if changed_buckets.length > 0
89-
message = <<~MESSAGE.red
102+
message = <<-MESSAGE.red
90103
⚠️ Deprecation warnings have changed!
91104
92105
Code called by the following spec files is now generating different deprecation warnings:
@@ -119,7 +132,7 @@ def save
119132
new_shitlist = create_temp_shitlist
120133
FileUtils.cp(new_shitlist.path, shitlist_path)
121134
ensure
122-
new_shitlist&.delete
135+
new_shitlist.delete if new_shitlist
123136
end
124137

125138
def create_temp_shitlist

spec/deprecation_tracker_spec.rb

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
RSpec.describe DeprecationTracker do
66
let(:shitlist_path) do
7-
shitlist_path = Tempfile.new.path
7+
shitlist_path = Tempfile.new("tmp").path
88
FileUtils.rm(shitlist_path)
99
shitlist_path
1010
end
@@ -92,14 +92,14 @@
9292

9393
subject.save
9494

95-
expected_json = <<~JSON.chomp
96-
{
97-
"bucket 1": [
98-
"a",
99-
"b",
100-
"b"
101-
]
102-
}
95+
expected_json = <<-JSON.chomp
96+
{
97+
"bucket 1": [
98+
"a",
99+
"b",
100+
"b"
101+
]
102+
}
103103
JSON
104104
expect(File.read(shitlist_path)).to eq(expected_json)
105105
end
@@ -116,15 +116,15 @@
116116
subject.add("a")
117117
subject.save
118118

119-
expected_json = <<~JSON.chomp
120-
{
121-
"bucket 1": [
122-
"a"
123-
],
124-
"bucket 2": [
125-
"a"
126-
]
127-
}
119+
expected_json = <<-JSON.chomp
120+
{
121+
"bucket 1": [
122+
"a"
123+
],
124+
"bucket 2": [
125+
"a"
126+
]
127+
}
128128
JSON
129129
expect(File.read(shitlist_path)).to eq(expected_json)
130130
end
@@ -141,12 +141,12 @@
141141
subject.add("b")
142142
subject.save
143143

144-
expected_json = <<~JSON.chomp
145-
{
146-
"bucket 1": [
147-
"b"
148-
]
149-
}
144+
expected_json = <<-JSON.chomp
145+
{
146+
"bucket 1": [
147+
"b"
148+
]
149+
}
150150
JSON
151151
expect(File.read(shitlist_path)).to eq(expected_json)
152152
end
@@ -159,15 +159,15 @@
159159
subject.add("a")
160160
subject.save
161161

162-
expected_json = <<~JSON.chomp
163-
{
164-
"bucket 1": [
165-
"a"
166-
],
167-
"bucket 2": [
168-
"a"
169-
]
170-
}
162+
expected_json = <<-JSON.chomp
163+
{
164+
"bucket 1": [
165+
"a"
166+
],
167+
"bucket 2": [
168+
"a"
169+
]
170+
}
171171
JSON
172172
expect(File.read(shitlist_path)).to eq(expected_json)
173173
end
@@ -180,14 +180,14 @@
180180
subject.add("a")
181181
subject.save
182182

183-
expected_json = <<~JSON.chomp
184-
{
185-
"bucket 1": [
186-
"a",
187-
"b",
188-
"c"
189-
]
190-
}
183+
expected_json = <<-JSON.chomp
184+
{
185+
"bucket 1": [
186+
"a",
187+
"b",
188+
"c"
189+
]
190+
}
191191
JSON
192192
expect(File.read(shitlist_path)).to eq(expected_json)
193193
end

0 commit comments

Comments
 (0)