Skip to content

Commit dc93735

Browse files
committed
Merge pull request #84 from grosser/grosser/env
deprecate TO_FILE and make all private methods private
2 parents 109173b + 3495eaa commit dc93735

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

lib/code_climate/test_reporter/formatter.rb

Lines changed: 14 additions & 9 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,15 @@ def format(result)
3636
false
3737
end
3838

39+
# actually private ...
40+
def short_filename(filename)
41+
return filename unless ::SimpleCov.root
42+
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
43+
apply_prefix filename
44+
end
45+
46+
private
47+
3948
def partial?
4049
tddium?
4150
end
@@ -81,13 +90,6 @@ def to_payload(result)
8190
}
8291
end
8392

84-
85-
def short_filename(filename)
86-
return filename unless ::SimpleCov.root
87-
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
88-
apply_prefix filename
89-
end
90-
9193
def tddium?
9294
ci_service_data && ci_service_data[:name] == "tddium"
9395
end
@@ -98,7 +100,10 @@ def round(numeric, precision)
98100
Float(numeric).round(precision)
99101
end
100102

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

103108
def apply_prefix filename
104109
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)