Skip to content

Commit

Permalink
Stop handling string filters as regexps
Browse files Browse the repository at this point in the history
Previously, filter strings passed to `add_filter` have been handled as regexps.
It means, for example, `add_filter '.pl'` matches against 'sample.rb'
because `.` is handled as _any character_ in regexp.

As now we have [regexp filter](simplecov-ruby#589),
there's no reason to handle filter strings as regexps.

However we need to think about semver with this change.
If this behavior was intentional,
we cannot introduce this change until next major version bump.
Or we can do if this was a _bug_.
  • Loading branch information
yujinakayama committed Aug 27, 2017
1 parent d0e0c9b commit 52f982e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simplecov/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class StringFilter < SimpleCov::Filter
# Returns true when the given source file's filename matches the
# string configured when initializing this Filter with StringFilter.new('somestring)
def matches?(source_file)
(source_file.project_filename =~ /#{filter_argument}/)
source_file.project_filename.include?(filter_argument)
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject
end

it "doesn't match a new SimpleCov::StringFilter '.pl'" do
expect(SimpleCov::StringFilter.new(".pl")).not_to be_matches subject
end

it "doesn't match a parent directory with a new SimpleCov::StringFilter" do
parent_dir_name = File.basename(File.expand_path("..", File.dirname(__FILE__)))
expect(SimpleCov::StringFilter.new(parent_dir_name)).not_to be_matches subject
Expand Down

0 comments on commit 52f982e

Please sign in to comment.