Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 5fbfae3

Browse files
committed
deprecate TO_FILE and make all private methods private
1 parent 109173b commit 5fbfae3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/code_climate/test_reporter/formatter.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def format(result)
1919

2020
payload = to_payload(result)
2121
PayloadValidator.validate(payload)
22-
if tddium? || ENV["TO_FILE"]
22+
if write_to_file?
2323
file_path = File.join(Dir.tmpdir, "codeclimate-test-coverage-#{SecureRandom.uuid}.json")
2424
print "Coverage results saved to #{file_path}... "
2525
File.open(file_path, "w") { |file| file.write(payload.to_json) }
@@ -36,6 +36,8 @@ def format(result)
3636
false
3737
end
3838

39+
private
40+
3941
def partial?
4042
tddium?
4143
end
@@ -81,7 +83,6 @@ def to_payload(result)
8183
}
8284
end
8385

84-
8586
def short_filename(filename)
8687
return filename unless ::SimpleCov.root
8788
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
@@ -98,7 +99,10 @@ def round(numeric, precision)
9899
Float(numeric).round(precision)
99100
end
100101

101-
private
102+
def write_to_file?
103+
warn "TO_FILE is deprecated, use CODECLIMATE_TO_FILE" if ENV["TO_FILE"]
104+
tddium? || ENV["CODECLIMATE_TO_FILE"] || ENV["TO_FILE"]
105+
end
102106

103107
def apply_prefix filename
104108
prefix = CodeClimate::TestReporter.configuration.path_prefix

spec/lib/formatter_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ module CodeClimate::TestReporter
108108

109109
describe '#short_filename' do
110110
it 'should return the filename of the file relative to the SimpleCov root' do
111-
expect(formatter.short_filename('file1')).to eq('file1')
112-
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('file1')
111+
expect(formatter.send(:short_filename, 'file1')).to eq('file1')
112+
expect(formatter.send(:short_filename, "#{::SimpleCov.root}/file1")).to eq('file1')
113113
end
114114

115115
context "with path prefix" do
@@ -126,8 +126,8 @@ module CodeClimate::TestReporter
126126
end
127127

128128
it 'should include the path prefix if set' do
129-
expect(formatter.short_filename('file1')).to eq('custom/file1')
130-
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('custom/file1')
129+
expect(formatter.send(:short_filename, 'file1')).to eq('custom/file1')
130+
expect(formatter.send(:short_filename, "#{::SimpleCov.root}/file1")).to eq('custom/file1')
131131
end
132132
end
133133
end

0 commit comments

Comments
 (0)