SimpleCovBadge is a gem that can be added to the Gemfile
and will produce a file called coverage_badge.png
in the coverage
directory.
It could be looking as follows dependent on how it is configured.
The idea is to created a badge for SimpleCov to create a persistable image that shows the coverage in percent as a badge.
The badge creation is dependent on the Repo-small-badge gem which creates and SVG badge.
It can be installed in your Ruby library or rails app as part of the Gemfile
as follows.
# In your gemfile
gem 'simplecov-small-badge', :require => false
This gem is an alternative and inspired by the great work in the other gem simplecov-badge which does a similar badge but looks different and cannot easily made small. So it's mostly an optical alternative.
Whereever you are integrating SimpleCov
you can configure the SimpleCovSmallBadge
gem as any formater can be configured. The default integration could looks as follows:
require 'simplecov_small_badge'
# Wherever your SimpleCov.start block is (spec_helper.rb, test_helper.rb, or .simplecov)
SimpleCov.start do
# add your normal SimpleCov configs
add_filter "/app/model"
# call SimpleCov::Formatter::BadgeFormatter after the normal HTMLFormatter
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
SimpleCovSmallBadge::Formatter
])
end
# configure any options you want for SimpleCov::Formatter::BadgeFormatter
SimpleCovSmallBadge.configure do |config|
# does not created rounded borders
config.rounded_border = true
# set the background for the title to darkgrey
config.background = '#ffffcc'
end
This process is split into two steps.
-
You need to create an access token for you github repository that can be configured to travis to allow password-less pushing. This is described in Github Help - Authenticating to GitHub / Creating a personal access token for the command line
-
Configure travis to push the result to github-pages inspired from the Travis description and configuration to be found in .travis.yml
-
Integrate your badge into the README.md as follows
![Coverage](https://marcgrimme.github.io/simplecov-small-badge/badges/coverage_badge_total.png)
The behaviour of SimpleCovSmallBadge
can be influenced by configuration options as defined in the configuration class.
After checking out the repo, run bundle update
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
- Fork it ( https://github.com/marcgrimme/simplecov-small-badge/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request