diff --git a/features/config_root.feature b/features/config_root.feature new file mode 100644 index 00000000..67b2d432 --- /dev/null +++ b/features/config_root.feature @@ -0,0 +1,26 @@ +@rspec @disable-bundler + +Feature: + + The root of the project can be customized. + + Background: + Given I'm working on the project "monorepo" + + Scenario: A coverage result is considered if it falls inside the root of the project + Given I install dependencies + And a file named ".simplecov" with: + """ + SimpleCov.start do + root __dir__ + end + """ + When I open the coverage report generated with `bin/rspec_binstub_that_chdirs extra/spec/extra_spec.rb` + Then I should see the groups: + | name | coverage | files | + | All Files | 100.0% | 2 | + + And I should see the source files: + | name | coverage | + | base/lib/monorepo/base.rb | 100.00 % | + | extra/lib/monorepo/extra.rb | 100.00 % | 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/test_projects/monorepo/Gemfile b/test_projects/monorepo/Gemfile new file mode 100644 index 00000000..321c568b --- /dev/null +++ b/test_projects/monorepo/Gemfile @@ -0,0 +1,15 @@ +source "https://rubygems.org" + +gem "rspec" + +gem "base", path: "base" +gem "extra", path: "extra" + +# when the tests are executed the project is in tmp/aruba/project +# which is a different nesting from its usual place +root = File.expand_path("../..", __dir__) +unless File.exist?("#{root}/simplecov.gemspec") + root = File.expand_path("../../..", __dir__) +end + +gem "simplecov", path: root diff --git a/test_projects/monorepo/Gemfile.lock b/test_projects/monorepo/Gemfile.lock new file mode 100644 index 00000000..9ffeb930 --- /dev/null +++ b/test_projects/monorepo/Gemfile.lock @@ -0,0 +1,49 @@ +PATH + remote: ../.. + specs: + simplecov (0.18.5) + docile (~> 1.1) + simplecov-html (~> 0.11) + +PATH + remote: base + specs: + base (0.0.1) + +PATH + remote: extra + specs: + extra (0.0.1) + base + +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.3) + docile (1.3.2) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.2) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.3) + simplecov-html (0.12.2) + +PLATFORMS + ruby + +DEPENDENCIES + base! + extra! + rspec + simplecov! + +BUNDLED WITH + 2.1.4 diff --git a/test_projects/monorepo/base/base.gemspec b/test_projects/monorepo/base/base.gemspec new file mode 100644 index 00000000..0ecc7460 --- /dev/null +++ b/test_projects/monorepo/base/base.gemspec @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +Gem::Specification.new do |gem| + gem.name = "base" + gem.version = "0.0.1" + gem.authors = ["Someone"] + gem.email = ["someonesemail"] + gem.homepage = "https://example.org" + gem.summary = "Base stuff" + gem.description = %(Base stuff, really) + gem.license = "MIT" + gem.files = ["lib/monorepo/base.rb"] +end diff --git a/test_projects/monorepo/base/lib/monorepo/base.rb b/test_projects/monorepo/base/lib/monorepo/base.rb new file mode 100644 index 00000000..e5ce7d95 --- /dev/null +++ b/test_projects/monorepo/base/lib/monorepo/base.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Monorepo + class Base + def initialize(label) + @label = label + end + + def reverse + @label.reverse + end + end +end diff --git a/test_projects/monorepo/bin/rspec_binstub_that_chdirs b/test_projects/monorepo/bin/rspec_binstub_that_chdirs new file mode 100755 index 00000000..46f94696 --- /dev/null +++ b/test_projects/monorepo/bin/rspec_binstub_that_chdirs @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require "bundler/setup" + +if ARGV[0] + cleaned_file_path = ARGV[0].split("./").last + argument_parts = cleaned_file_path.split("/") + + first_part = argument_parts[0] + + if File.directory?(first_part) + Dir.chdir(first_part) + + other_parts = argument_parts[1..-1] + + new_args = [!other_parts.empty? ? other_parts.join("/") : nil, *ARGV[1..-1]].compact + + ARGV.replace(new_args) + end +end + +load Gem.bin_path("rspec-core", "rspec") diff --git a/test_projects/monorepo/extra/extra.gemspec b/test_projects/monorepo/extra/extra.gemspec new file mode 100644 index 00000000..2ebeea71 --- /dev/null +++ b/test_projects/monorepo/extra/extra.gemspec @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +Gem::Specification.new do |gem| + gem.name = "extra" + gem.version = "0.0.1" + gem.authors = ["Someone"] + gem.email = ["someonesemail"] + gem.homepage = "https://example.org" + gem.summary = "Extra stuff" + gem.description = %(Extra stuff, really) + gem.license = "MIT" + gem.add_dependency "base" + gem.files = ["lib/monorepo/extra.rb"] +end diff --git a/test_projects/monorepo/extra/lib/monorepo/extra.rb b/test_projects/monorepo/extra/lib/monorepo/extra.rb new file mode 100644 index 00000000..66ba0e8d --- /dev/null +++ b/test_projects/monorepo/extra/lib/monorepo/extra.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "monorepo/base" + +module Monorepo + class Extra + def initialize(label) + @label = label + end + + def identity + Base.new(Base.new(@label).reverse).reverse + end + end +end diff --git a/test_projects/monorepo/extra/spec/extra_spec.rb b/test_projects/monorepo/extra/spec/extra_spec.rb new file mode 100644 index 00000000..89870590 --- /dev/null +++ b/test_projects/monorepo/extra/spec/extra_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "spec_helper" +require "monorepo/extra" + +RSpec.describe Monorepo::Extra do + describe "#identity" do + it "returns the same string" do + expect(described_class.new("foo").identity).to eq("foo") + end + end +end diff --git a/test_projects/monorepo/extra/spec/spec_helper.rb b/test_projects/monorepo/extra/spec/spec_helper.rb new file mode 100644 index 00000000..0f2df07a --- /dev/null +++ b/test_projects/monorepo/extra/spec/spec_helper.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +require "simplecov" + +require "monorepo/base"