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

Commit 95e413a

Browse files
committed
Don't remove the simplecov root more than once
If you have a rails app in a directory named `/app`, you will remove too much. Make sure we're only removing the first instance of it.
1 parent 4e29518 commit 95e413a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/code_climate/test_reporter/formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def format(result)
3939
# actually private ...
4040
def short_filename(filename)
4141
return filename unless ::SimpleCov.root
42-
filename = filename.gsub(::SimpleCov.root, ".").gsub(/^\.\//, "")
42+
filename = filename.gsub(/^#{::SimpleCov.root}/, ".").gsub(/^\.\//, "")
4343
apply_prefix filename
4444
end
4545

spec/lib/formatter_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ module CodeClimate::TestReporter
131131
expect(formatter.send(:short_filename, "#{::SimpleCov.root}/file1")).to eq('custom/file1')
132132
end
133133
end
134+
135+
it "should not strip the subdirectory if it has the same name as the root" do
136+
expect(formatter.send(:short_filename, "#{::SimpleCov.root}/#{::SimpleCov.root}/file1")).to eq("#{::SimpleCov.root}/file1")
137+
end
134138
end
135139
end
136140
end

0 commit comments

Comments
 (0)