From 03f6470b411905aa2d87590fc3f71269e055821d Mon Sep 17 00:00:00 2001 From: Craig Little Date: Sat, 13 Feb 2016 14:46:16 -0800 Subject: [PATCH] Make `track_files` work when configured with nil Fixes #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: * https://github.com/colszowka/simplecov/pull/447 * https://github.com/colszowka/simplecov/issues/462 --- lib/simplecov.rb | 4 ++-- lib/simplecov/configuration.rb | 11 +++++++++-- spec/configuration_spec.rb | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 spec/configuration_spec.rb diff --git a/lib/simplecov.rb b/lib/simplecov.rb index da88b055..19665f7c 100644 --- a/lib/simplecov.rb +++ b/lib/simplecov.rb @@ -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 diff --git a/lib/simplecov/configuration.rb b/lib/simplecov/configuration.rb index dec0ca26..23ddc143 100644 --- a/lib/simplecov/configuration.rb +++ b/lib/simplecov/configuration.rb @@ -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. # diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb new file mode 100644 index 00000000..c68ad557 --- /dev/null +++ b/spec/configuration_spec.rb @@ -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