Skip to content

Commit

Permalink
improve how we handled setting ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Mayer committed Jan 8, 2023
1 parent 7727105 commit 652a97a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions lib/coverband/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/coverband/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 652a97a

Please sign in to comment.