-
Notifications
You must be signed in to change notification settings - Fork 552
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
Fix regression in rails filters #618
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 using let with anonymous classes! :) |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait whaaaaatttttttttt? You can just use |
||
expect(filtered?(config, "config/environment.rb")).to be | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 great way of testing it on a lower level, thank you very much! 👍 |
||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly confused why this is here and not just above? Leftover? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if there's a scenario where you'd run the specs w/ SIMPLECOV_NO_DEFAULTS, but this should ensure the suite still passes in that case, since it has to do with the default filters. Might be worth setting up in Travis? |
||
|
||
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]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(with other point where it is I mean this here) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same story here, I just wanted to make this resilient in case people run specs with that set, since the profiles won't exist in that case.