Created
November 22, 2019 15:09
-
-
Save bronzdoc/e6e7f4f9e4abab7241a6dc9606c1536f to your computer and use it in GitHub Desktop.
Merging Multiple SimpleCov Coverage Results - Code snippet of https://www.fastruby.io/blog/rails/simplecov/upgrades/merging-multiple-simpleCov-coverage-results.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleCovMerger | |
def self.report_coverage(base_dir:, ci_project_path:, project_path:) | |
new(base_dir: base_dir, ci_project_path: ci_project_path, project_path: project_path).merge_results | |
end | |
attr_reader :base_dir, :ci_project_path, :project_path | |
def initialize(base_dir:, ci_project_path:, project_path:) | |
@base_dir = base_dir | |
@ci_project_path = ci_project_path | |
@project_path = project_path | |
end | |
def merge_results | |
require "simplecov" | |
require "json" | |
results = resultsets.map do |file| | |
hash_result = JSON.parse(clean(File.read(file))) | |
SimpleCov::Result.from_hash(hash_result) | |
end | |
result = SimpleCov::ResultMerger.merge_results(*results) | |
SimpleCov::ResultMerger.store_result(result) | |
end | |
private | |
def resultsets | |
Dir["#{base_dir}/.resultset-*.json"] | |
end | |
def clean(results) | |
results.gsub(ci_project_path, project_path) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment