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 cffb463 commit 67a26d4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 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
13 changes: 10 additions & 3 deletions lib/simplecov/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ 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?
@track_files = glob
def track_files(glob)
@tracked_files = glob
end

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

#
Expand Down
29 changes: 29 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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

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

0 comments on commit 67a26d4

Please sign in to comment.