Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/code_climate/test_reporter/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.configuration
end

class Configuration
attr_accessor :branch, :logger, :profile
attr_accessor :branch, :logger, :profile, :path_prefix

def logger
@logger ||= default_logger
Expand Down
9 changes: 8 additions & 1 deletion lib/code_climate/test_reporter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def calculate_blob_id(path)

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

def tddium?
Expand All @@ -99,6 +100,12 @@ def round(numeric, precision)

private

def apply_prefix filename
prefix = CodeClimate::TestReporter.configuration.path_prefix
return filename if prefix.nil?
"#{prefix}/#{filename}"
end

def ci_service_data
@ci_service_data ||= Ci.service_data
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module CodeClimate::TestReporter
expect(CodeClimate::TestReporter.configuration.logger).to be_instance_of Logger
expect(CodeClimate::TestReporter.configuration.logger.level).to eq Logger::INFO
expect(CodeClimate::TestReporter.configuration.profile).to eq('test_frameworks')
expect(CodeClimate::TestReporter.configuration.path_prefix).to be_nil
end
end

Expand Down Expand Up @@ -47,6 +48,19 @@ module CodeClimate::TestReporter

expect(CodeClimate::TestReporter.configuration.profile).to eq('custom')
end

it 'stores path prefix' do
CodeClimate::TestReporter.configure do |config|
config.path_prefix = 'custom'
end

expect(CodeClimate::TestReporter.configuration.path_prefix).to eq('custom')

CodeClimate::TestReporter.configure do |config|
config.path_prefix = nil
end

end
end
end
end
18 changes: 18 additions & 0 deletions spec/lib/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,22 @@ module CodeClimate::TestReporter
app.http_user_agent.should include("v#{CodeClimate::TestReporter::VERSION}")
end
end

describe '#short_filename' do
it 'should return the filename of the file relative to the SimpleCov root' do
CodeClimate::TestReporter::Formatter.new.short_filename('file1').should == 'file1'
CodeClimate::TestReporter::Formatter.new.short_filename("#{::SimpleCov.root}/file1").should == 'file1'
end

it 'should include the path prefix if set' do
CodeClimate::TestReporter.configure do |config|
config.path_prefix = 'custom'
end
CodeClimate::TestReporter::Formatter.new.short_filename('file1').should == 'custom/file1'
CodeClimate::TestReporter::Formatter.new.short_filename("#{::SimpleCov.root}/file1").should == 'custom/file1'
CodeClimate::TestReporter.configure do |config|
config.path_prefix = nil
end
end
end
end