Skip to content

Commit

Permalink
Fix regression in rails filters
Browse files Browse the repository at this point in the history
In converting this to a regex in a0b14a1, an extra leading `/` was added,
making this filter less useful (it would literally match the `/^/db/`
path).
  • Loading branch information
jenseng committed Aug 30, 2017
1 parent a50b654 commit 82f5873
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
load_profile "test_frameworks"

add_filter %r{^/config/}
add_filter %r{/^/db/}
add_filter %r{^/db/}

add_group "Controllers", "app/controllers"
add_group "Channels", "app/channels" if defined?(ActionCable)
Expand Down
41 changes: 41 additions & 0 deletions spec/defaults_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "helper"

if SimpleCov.usable?
describe SimpleCov do
skip "requires the default configuration" if ENV["SIMPLECOV_NO_DEFAULTS"]

context "profiles" do
let(:config_class) do
Class.new do
include SimpleCov::Configuration

def load_profile(name)
configure(&SimpleCov.profiles[name.to_sym])
end
end
end

let(:config) { config_class.new }

def filtered?(config, filename)
path = File.join(SimpleCov.root, filename)
file = SimpleCov::SourceFile.new(path, [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
config.filters.any? { |filter| filter.matches?(file) }
end

it "provides a sensible test_frameworks profile" do
config.load_profile(:test_frameworks)
expect(filtered?(config, "foo.rb")).not_to be
expect(filtered?(config, "test/foo.rb")).to be
expect(filtered?(config, "spec/bar.rb")).to be
end

it "provides a sensible rails profile" do
config.load_profile(:rails)
expect(filtered?(config, "app/models/user.rb")).not_to be
expect(filtered?(config, "db/schema.rb")).to be
expect(filtered?(config, "config/environment.rb")).to be
end
end
end
end
4 changes: 3 additions & 1 deletion spec/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def matches?(_)
end
end

context "with the default profile" do
context "with the default configuration" do
skip "requires the default configuration" if ENV["SIMPLECOV_NO_DEFAULTS"]

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])
Expand Down

0 comments on commit 82f5873

Please sign in to comment.