Skip to content

Commit

Permalink
Merge pull request #84 from grosser/grosser/env
Browse files Browse the repository at this point in the history
deprecate TO_FILE and make all private methods private
  • Loading branch information
noahd1 committed Apr 19, 2015
2 parents 109173b + 3495eaa commit dc93735
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
23 changes: 14 additions & 9 deletions lib/code_climate/test_reporter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def format(result)

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

# actually private ...
def short_filename(filename)
return filename unless ::SimpleCov.root
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
apply_prefix filename
end

private

def partial?
tddium?
end
Expand Down Expand Up @@ -81,13 +90,6 @@ def to_payload(result)
}
end


def short_filename(filename)
return filename unless ::SimpleCov.root
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
apply_prefix filename
end

def tddium?
ci_service_data && ci_service_data[:name] == "tddium"
end
Expand All @@ -98,7 +100,10 @@ def round(numeric, precision)
Float(numeric).round(precision)
end

private
def write_to_file?
warn "TO_FILE is deprecated, use CODECLIMATE_TO_FILE" if ENV["TO_FILE"]
tddium? || ENV["CODECLIMATE_TO_FILE"] || ENV["TO_FILE"]
end

def apply_prefix filename
prefix = CodeClimate::TestReporter.configuration.path_prefix
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ module CodeClimate::TestReporter

describe '#short_filename' do
it 'should return the filename of the file relative to the SimpleCov root' do
expect(formatter.short_filename('file1')).to eq('file1')
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('file1')
expect(formatter.send(:short_filename, 'file1')).to eq('file1')
expect(formatter.send(:short_filename, "#{::SimpleCov.root}/file1")).to eq('file1')
end

context "with path prefix" do
Expand All @@ -126,8 +126,8 @@ module CodeClimate::TestReporter
end

it 'should include the path prefix if set' do
expect(formatter.short_filename('file1')).to eq('custom/file1')
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('custom/file1')
expect(formatter.send(:short_filename, 'file1')).to eq('custom/file1')
expect(formatter.send(:short_filename, "#{::SimpleCov.root}/file1")).to eq('custom/file1')
end
end
end
Expand Down

0 comments on commit dc93735

Please sign in to comment.