Add Achievement Badges to Your Gem README

I really enjoy crashing into a gem with a markdown-ready README file that includes top badges telling me things like the current available gem version, the fact that is continuously being tested using travis or knowing the developer cares about the gem dependencies being up-to-date!

Take a look how this looks like in thor or some tiny gem of mine.

Achieving all that will take some steps, here is how:

How the badges will look like

Gem Version Build Status Dependency Status Code Climate Coverage Status

Where to sign-up

Getting your code ready to use them

Gem version, code climate and gem dependencies do not require more work on your side besides pushing your updates to github, those services will take care of the rest.

Travis-CI

Add this .travis.yml file to your project root, change it depending on the ruby versions you are interested to support:

1
2
3
4
5
language: ruby
rvm:
  - 1.9.3
  - 2.0.0
  - jruby-1.7.9

Coveralls with SimpleCov

I use SimpleCov for test coverage, coveralls gem take care of your badge,

Add necessary dependencies to your gemspec:

1
2
s.add_development_dependency "simplecov", ">= 0.8.2"
s.add_development_dependency 'coveralls', '>= 0.7.0'

If you use rspec, update your spec_helper.rb and add this lines to the very beginning:

1
2
3
4
5
6
7
8
require 'simplecov'
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
  SimpleCov::Formatter::HTMLFormatter,
  Coveralls::SimpleCov::Formatter
]
SimpleCov.start

Update your README file

Replace strings elgalu with your github user and boolean_class with your github repo name. It’s probably a better idea that you use a templating tool for this like the one I built and use

# TODO: Your gem name

[![Gem Version][GV img]][Gem Version]
[![Build Status][BS img]][Build Status]
[![Dependency Status][DS img]][Dependency Status]
[![Code Climate][CC img]][Code Climate]
[![Coverage Status][CS img]][Coverage Status]

## Description

TODO: Your gem description

[Gem Version]: https://rubygems.org/gems/boolean_class
[Build Status]: https://travis-ci.org/elgalu/boolean_class
[travis pull requests]: https://travis-ci.org/elgalu/boolean_class/pull_requests
[Dependency Status]: https://gemnasium.com/elgalu/boolean_class
[Code Climate]: https://codeclimate.com/github/elgalu/boolean_class
[Coverage Status]: https://coveralls.io/r/elgalu/boolean_class

[GV img]: https://badge.fury.io/rb/boolean_class.png
[BS img]: https://travis-ci.org/elgalu/boolean_class.png
[DS img]: https://gemnasium.com/elgalu/boolean_class.png
[CC img]: https://codeclimate.com/github/elgalu/boolean_class.png
[CS img]: https://coveralls.io/repos/elgalu/boolean_class/badge.png?branch=master

Don’t forget to let me know if i’m missing new cool badges out there!

Google Analytics

I’ve recently added githalytics service in order to have Google Analytics for each of my github repos. Note there is also bitdeli service but haven’t tested it yet, let me know if is better or more free.

To do so:

  1. Go to Google Analytics website and signup to get your Property ID, e.g.

     Default URL protocol: https://
     Default URL source..: github.com/elgalu/time_ago_in_words
    

    You may also delete github.com from your GA Referral Exclusion List

  2. Go to githalytics and sign up, e.g.

     TrackingCode[url]:  https://github.com/elgalu/time_ago_in_words
     TrackingCode[code]: UA-12345-12
    
  3. Add the fake image badge that will send data for analytics purposes, e.g.

     [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/3fe2425a26ab0ca00b5bc6acf817af59 "githalytics.com")](http://githalytics.com/elgalu/time_ago_in_words)
    

That should be it. Remember to check later on Google Analytics site for the collected data, works like a charm!

Comments