Skip to content

Commit

Permalink
Make track_files work when configured with nil
Browse files Browse the repository at this point in the history
Fixes simplecov-ruby#462.

The implementation of `track_files` was refactored recently to suppress
a warning in the underlying instance variable had not been initialized.
This had the effect of changing the behavior when trying to nullify the
default configuration of tracked files in some cases through the use of
nil.

With this change, a declaration of `track_files nil` will once again
clear out any previous configuration and essentially disable the
feature.

Reference:
  * simplecov-ruby#447
  * simplecov-ruby#462
  • Loading branch information
craiglittle committed Feb 13, 2016
1 parent 15ec12e commit 4058c2b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def start(profile = nil, &block)
# their coverage to zero.
#
def add_not_loaded_files(result)
if track_files
if tracked_files
result = result.dup
Dir[track_files].each do |file|
Dir[tracked_files].each do |file|
absolute = File.expand_path(file)

result[absolute] ||= [0] * File.foreach(absolute).count
Expand Down
11 changes: 9 additions & 2 deletions lib/simplecov/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ def coverage_path
# or not they were explicitly required. Without this, un-required files
# will not be present in the final report.
#
def track_files(glob = nil)
return @track_files if defined?(@track_files) && glob.nil?
def track_files(glob)
@track_files = glob
end

#
# Returns the glob that will be used to include files that were not
# explicitly required.
#
def tracked_files
@track_files if defined?(@track_files)
end

#
# Returns the list of configured filters. Add filters using SimpleCov.add_filter.
#
Expand Down
23 changes: 23 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "helper"

describe SimpleCov::Configuration do
describe "#tracked_files" do
context "when configured" do
let(:glob) { "{app,lib}/**/*.rb" }

before { SimpleCov.track_files(glob) }

it "returns the configured glob" do
expect(SimpleCov.tracked_files).to eq glob
end

context "and configured again with nil" do
before { SimpleCov.track_files(nil) }

it "returns nil" do
expect(SimpleCov.tracked_files).to be_nil
end
end
end
end
end

0 comments on commit 4058c2b

Please sign in to comment.