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

Fix regression in rails filters #618

Merged
merged 1 commit into from
Sep 2, 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 @@ -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"]
Copy link
Collaborator

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) :)

Copy link
Contributor Author

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.


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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait whaaaaatttttttttt? You can just use .to be/.not_to be. Touché. I've used rspec forever and consider myself pretty good at it bu you constantly teach me new stuff. Thanks 🙏

expect(filtered?(config, "config/environment.rb")).to be
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
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"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Slightly confused why this is here and not just above? Leftover? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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