Skip to content

Commit

Permalink
Merge pull request #717 from deivid-rodriguez/weird_root
Browse files Browse the repository at this point in the history
Support project roots with special characters
  • Loading branch information
amatsuda committed May 20, 2019
2 parents c65a108 + 1c0cac6 commit 470587c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simplecov/source_file.rb
Expand Up @@ -84,7 +84,7 @@ def initialize(filename, coverage)

# The path to this source file relative to the projects directory
def project_filename
@filename.sub(/^#{SimpleCov.root}/, "")
@filename.sub(Regexp.new("^#{Regexp.escape(SimpleCov.root)}"), "")
end

# The source code for this file. Aliased as :source
Expand Down
19 changes: 19 additions & 0 deletions spec/source_file_spec.rb
Expand Up @@ -22,6 +22,25 @@
expect(subject.project_filename).to eq("/spec/fixtures/sample.rb")
end

context "when project_root contains special characters" do
let(:root) { File.expand_path("foo[]bar") }

around do |example|
old_root = SimpleCov.root
SimpleCov.root(root)
begin
example.run
ensure
SimpleCov.root(old_root)
end
end

it "works" do
source_file = SimpleCov::SourceFile.new(File.expand_path("sample.rb", root), COVERAGE_FOR_SAMPLE_RB)
expect(source_file.project_filename).to eq("/sample.rb")
end
end

it "has source_lines equal to lines" do
expect(subject.lines).to eq(subject.source_lines)
end
Expand Down

0 comments on commit 470587c

Please sign in to comment.