Skip to content

matthew342/simplecov-badge

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Badge formatter for SimpleCov

Codeship Status for matthew342/simplecov-badge Code Coverage for matthew342/simplecov-badge

Generates coverage badges from SimpleCov using ImageMagick. Great for small private repos that don't want to pay for a hosted service. Add the badge to your readme, linked to your coverage report for improved test coverage visibility.

Note: To learn more about SimpleCov, check out the main repo at https://github.com/colszowka/simplecov

Examples

The left side of the badge shows and is color-coded for the percentage of lines covered. The right side is color-coded for the strength of coverage (in terms of hits/line). ####Simple

Code Coverage for matthew342/simplecov-badge ####Including Group sub-badges and timestamp

Code Coverage for matthew342/simplecov-badge

Installation

Install ImageMagick, then:

# In your gemfile
gem 'simplecov-badge', :require => false

Usage

# Wherever your SimpleCov.start block is (spec_helper.rb, test_helper.rb, or .simplecov)
SimpleCov.start 'rails' do
	require 'simplecov-badge'
	# add your normal SimpleCov configs
	add_filter "/app/admin/"
	# configure any options you want for SimpleCov::Formatter::BadgeFormatter
	SimpleCov::Formatter::BadgeFormatter.generate_groups = true
	SimpleCov::Formatter::BadgeFormatter.strength_foreground = true
	SimpleCov::Formatter::BadgeFormatter.timestamp = true
	# call SimpleCov::Formatter::BadgeFormatter after the normal HTMLFormatter
	SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
		SimpleCov::Formatter::HTMLFormatter,
		SimpleCov::Formatter::BadgeFormatter,
	]
end

Use with your CI

Your badge will be generated in the /coverage directory of your project folder. From there, you can push it wherever you like. Two common options are to push to S3 or to push to GitHub Pages.

####If you want to store your coverage reports in GitHub Pages

You can do something like this as the last step in your build/deploy (assuming you've already created an orphan gh-pages branch):

mkdir ../tmp-coverage
cp -r coverage/ ../tmp-coverage/
git config --global user.email "CI@example.com"
git config --global user.name "CI Server"
cd ..
git clone --branch gh-pages  git@github.com:matthew342/simplecov-badge.git gh-pages-clone
cd gh-pages-clone
cp -r ../tmp-coverage/. .
rm -r ../tmp-coverage
git add .
git commit -a -m "CI: Coverage for $COMMIT_ID"
git push origin gh-pages:gh-pages

REMEMBER Gitub Pages are public - so if your repo is private pushing somewhere else might be a better idea.

####If you want to store your coverage reports in S3

Use one of the S3 wrappers for your language to automate pushing the files into an access-controlled S3 bucket. I use the S3 gem.

Options

Set these in your SimpleCov.start block - see Usage section.

Name Description Default
badge_titleCenter section of badge 'TEST COVERAGE'
generate_groups Whether to generate sub-badges for each group under the main badgetrue
timestamp Stick a timestamp on the bottom of the badge false
green The specific color to be used for 'green' '#4fb151'
yellow The specific color to be used for 'yellow' '#ded443'
red The specific color to be used for 'red' '#a23e3f'
number_font The font to use for the coverage percentage (for the main badge) 'Helvetica-Narrow-Bold'
number_font_size Size of font to use for the coverage percentage (for the main badge) 20
name_font The font to use for the name portion of the badge (of the main badge) 'Helvetica'
name_font_size Size of font to use for the name portion (of the main badge) 17
badge_height Height of the badge 27
strength_foreground Whether to color the foreground instead of the background when coloring the strength portion of the badge false
color_code_titleWhether to color the middle section of the badge. If true, will be colored according to the lowest color of the coverage and strength sections true
group_number_font Same as above, but for group sub-badges 'Helvetica-Narrow-Bold'
group_number_font_size Same as above, but for group sub-badges 18
group_name_font Same as above, but for group sub-badges 'Helvetica-Bold'
group_name_font_size Same as above, but for group sub-badges 15
group_badge_height Same as above, but for group sub-badges 22
group_strength_foreground Same as above, but for group sub-badgesfalse
group_color_code_titleSame as above, but for group sub-badges true

Note on Patches/Pull Requests

Pull requests are much appreciated - but please add tests! Run the test suite by cloning down the repo, then:

bundle install
rspec

Copyright

Adapted from simplecov-html.
Thanks to Christoph Olszowka. Copyright (c) 2013 Matt Hale. See LICENSE for details.

About

Badge formatter for SimpleCov code coverage tool for ruby 1.9+

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%