Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter directories outside SimpleCov.root that have it as a prefix #617

Merged
merged 1 commit into from
Aug 29, 2017
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/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Exclude all files outside of simplecov root
root_filter = nil
add_filter do |src|
root_filter ||= /\A#{Regexp.escape(SimpleCov.root)}/io
root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

src.filename !~ root_filter
end
end
Expand Down
28 changes: 28 additions & 0 deletions spec/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,34 @@ def matches?(_)
end
end

context "with the default profile" do
def a_file(path)
path = File.join(SimpleCov.root, path) unless path.start_with?("/")
SimpleCov::SourceFile.new(path, [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
end

context "inside the project" do
it "doesn't filter" do
expect(SimpleCov.filtered([a_file("foo.rb")]).count).to eq(1)
end

it "filters vendor/bundle" do
expect(SimpleCov.filtered([a_file("vendor/bundle/foo.rb")]).count).to eq(0)
end
end

context "outside the project" do
it "filters" do
expect(SimpleCov.filtered([a_file("/other/path/foo.rb")]).count).to eq(0)
end

it "filters even if the sibling directory has SimpleCov.root as a prefix" do
sibling_dir = SimpleCov.root + "_cache"
expect(SimpleCov.filtered([a_file(sibling_dir + "/foo.rb")]).count).to eq(0)
end
end
end

describe ".class_for_argument" do
it "returns SimpleCov::StringFilter for a string" do
expect(SimpleCov::Filter.class_for_argument("filestring")).to eq(SimpleCov::StringFilter)
Expand Down