diff --git a/lib/simplecov/useless_results_remover.rb b/lib/simplecov/useless_results_remover.rb index 464576bb..5d45604a 100644 --- a/lib/simplecov/useless_results_remover.rb +++ b/lib/simplecov/useless_results_remover.rb @@ -5,12 +5,14 @@ module SimpleCov # Select the files that related to working scope directory of SimpleCov # module UselessResultsRemover - ROOT_REGX = /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io.freeze - def self.call(coverage_result) coverage_result.select do |path, _coverage| - path =~ ROOT_REGX + path =~ root_regx end end + + def self.root_regx + @root_regx ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/i.freeze + end end end diff --git a/spec/useless_results_remover_spec.rb b/spec/useless_results_remover_spec.rb index 223b8f55..249dec11 100644 --- a/spec/useless_results_remover_spec.rb +++ b/spec/useless_results_remover_spec.rb @@ -32,4 +32,25 @@ expect(subject).to have_key(source_path) expect(subject[source_path]["lines"]).to be_kind_of(Array) end + + context "when changing coverage root" do + around do |example| + begin + previous_root_regx = SimpleCov::UselessResultsRemover.instance_variable_get(:@root_regx) + SimpleCov::UselessResultsRemover.instance_variable_set(:@root_regx, nil) + previous_root = SimpleCov.root + + SimpleCov.root "lib" + + example.run + ensure + SimpleCov.root previous_root + SimpleCov::UselessResultsRemover.instance_variable_set(:@root_regx, previous_root_regx) + end + end + + it "ignores stuff outside of the new coverage root" do + expect(subject).to be_empty + end + end end