ryancyq/rodiff

View on GitHub
tasks/coverage.rake

Summary

Maintainability
Test Coverage
# frozen_string_literal: true

namespace :coverage do
  desc "Run coverage with spec"
  task :run do
    Rake::Task[:spec].invoke(coverage: true)
  end

  desc "Collate coverage results generated by different test runners"
  task :report do
    require "simplecov"
    coverage_dir = File.join(File.dirname(SimpleCov.coverage_dir), "ruby-*")
    coverage_results = Dir[File.join(coverage_dir, ".resultset.json")]

    raise <<~MSG if coverage_results.empty?
      Coverage results not found, searched in:
      #{Dir[coverage_dir].map { |dir| "  - #{dir}" }.join("\n")}
    MSG

    SimpleCov.collate(coverage_results) do
      coverage_dir "coverage"
    end
  end
end

desc "Run coverage analysis and collate coverage results"
task coverage: ["coverage:run", "coverage:report"]