Skip to content

Instantly share code, notes, and snippets.

@ksss
Created December 14, 2020 06:57
Show Gist options
  • Save ksss/8bb546cb8e8ac24585b51ee0368f3007 to your computer and use it in GitHub Desktop.
Save ksss/8bb546cb8e8ac24585b51ee0368f3007 to your computer and use it in GitHub Desktop.
Minimum coverage on ruby gems
if ENV['COVERAGE']
require "coverage"
Coverage.start
at_exit do
# "great_library" is example gem name
cov = Coverage.result.select { |d| d.match?(%r{/great_library/lib/}) }
cov.transform_keys! { |key| key.dup.sub!(%r{^.*great_library/(lib/.*)$}, '\1') }
cov.transform_values! do |ary|
ary = ary.compact
ary.count { |l| l > 0 }.fdiv(ary.length)
end
max_length = cov.keys.max_by(&:length).length
puts "Coverage"
cov.to_a.sort_by { |k, v| v }.each do |k, v|
puts "| %-#{max_length}s | %6.2f %% |" % [k, v * 100]
end
end
end
# require "great_library"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment