From 652a97a42d9bdd0a93dd1ecdd751ea8592cdc33c Mon Sep 17 00:00:00 2001 From: Dan Mayer Date: Sun, 8 Jan 2023 15:08:09 -0700 Subject: [PATCH] improve how we handled setting ignores --- README.md | 6 +++--- lib/coverband/configuration.rb | 3 +++ test/coverband/configuration_test.rb | 10 ++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1c5532a7..667417d4 100644 --- a/README.md +++ b/README.md @@ -207,9 +207,9 @@ config.ignore += ['config/application.rb', 'config/boot.rb', 'config/puma.rb', 'config/schedule.rb', - 'bin/*', - 'config/environments/*', - 'lib/tasks/*'] + 'bin/.*', + 'config/environments/.*', + 'lib/tasks/.*'] ``` **Ignoring Custom Gem Locations:** Note, if you have your gems in a custom location under your app folder you likely want to add them to `config.ignore`. For example, if you have your gems not in a default ignored location of `app/vendor` but have them in `app/gems` you would need to add `gems/*` to your ignore list. diff --git a/lib/coverband/configuration.rb b/lib/coverband/configuration.rb index 734e06a0..33e9eaaf 100644 --- a/lib/coverband/configuration.rb +++ b/lib/coverband/configuration.rb @@ -177,7 +177,10 @@ def search_paths=(path_array) # Don't allow the ignore to override things like gem tracking ### def ignore=(ignored_array) + ignored_array.map { |ignore_str| Regexp.new(ignore_str) } @ignore = (@ignore + ignored_array).uniq + rescue RegexpError + logger.error "an invalid regular expression was passed in, ensure string are valid regex patterns #{ignored_array.join(",")}" end def current_root diff --git a/test/coverband/configuration_test.rb b/test/coverband/configuration_test.rb index 2a798ff6..41416bce 100644 --- a/test/coverband/configuration_test.rb +++ b/test/coverband/configuration_test.rb @@ -38,6 +38,16 @@ def setup assert_equal expected, Coverband.configuration.ignore end + test "ignore catches regex errors" do + Coverband.configuration.logger.expects(:error).with("an invalid regular expression was passed in, ensure string are valid regex patterns *invalidRegex*") + Coverband.configure do |config| + config.ignore = ["*invalidRegex*"] + end + Coverband::Collectors::Coverage.instance.reset_instance + expected = Coverband::Configuration::IGNORE_DEFAULTS << "config/environments" + assert_equal expected, Coverband.configuration.ignore + end + test "ignore" do Coverband::Collectors::Coverage.instance.reset_instance assert !Coverband.configuration.ignore.first.nil?