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..2c88f7a4 --- /dev/null +++ b/spec/configuration_spec.rb @@ -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