To monitor your code and show its quality in your Github Readmes you can add badges, such as for Travis CI (to show build status and test reports), Coveralls (code coverage reports), and Code Climate (code quality, a measurement out of 4). As well as seeing the status of your project’s code, clicking on the badges allow users to see detailed reports on these websites.
This tutorial shows you how to set up your project with these code reports. As well as this, it includes instructions for adding SimpleCov for code coverage data in your terminal and how to configure RSpec to print out more verbose test reports. This example is for ruby projects, but can be easily adapted to other languages. My Ruby tic tac toe tech test is one project where I used this setup.
- A Github account
- Started a ruby project and created a Github repo for it
- Knowledge of using RSpec for testing with Ruby
Setup your project
To add the testing setup to your project, add the following gems to your
Gemfile, then run
group :test do
gem 'coveralls', require: false
gem 'simplecov', require: false
gem 'simplecov-console', require: false
If you haven’t already initialized rspec for testing, enter
rspec -—init in your terminal in the root of your project directory. Add the following to the top of your
spec/spec_helper.rb . It gathers the code coverage data for Coveralls and SimpleCov.
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
# Want a nice code coverage website? Uncomment this next line!
To format the rspec output to be more verbose than a line of green dots. Add the following to
rspec in your terminal to see these reports. Here is an example of how it will look:
… and at the end you will see coverage report, including data for the lines and files covered.
Using Travis CI, Coveralls and Code Climate
You need to sign up for Travis CI, Coveralls, and Code Climate. Once you have done this, sync your github repos with them, and click on the switch to to select the github repo of the project you want to add.
.travis.yml to your project that contains the below code. This setup specifies which ruby version to use, to install the gems when building the project, then run rspec and the rake task to push the data to Coveralls.
- gem install bundler -v 1.15.1
- bundle exec rspec spec
- bundle exec rake coveralls:push
rspec and then pushes the data to
desc 'Run RSpec'
RSpec::Core::RakeTask.new do |t|
t.verbose = false
task default: :spec
To stop the coverage data being pushed to your github repo, add
/coverage/ to your
Add the badges to your Readme
Lastly, add the markdown for the badges in your
Readme.md (where you will add your own links to you github repo). Take out the spaces between the badges to show them all on the same line.
/ .svg?branch=master)](https://travis-ci.org/ /)
Now, add the files, commit and push to Github, and wait for Travis CI to build the project and send the data to Coveralls and Code Climate. Click on the badges to see more details of the code reports.