Improve your Ruby code quality with metrics

In the ruby world we have several tools to analyse our ruby (and Rails) code. In this article we will see the most used (and useful for me), and how to integrate into our CI process with Jenkins.

These gems are:

In your Gemfile you should include all gems:

 # Metrics
 gem 'simplecov', require: false
 gem 'simplecov-rcov', require: false
 gem 'rubocop', require: false
 gem 'rails_best_practices', require: false
 gem 'metric_fu', require: false

Simplecov needs some configuration at the beginning of your ‘spec_helper.rb’ to generate the coverage files:

require 'simplecov'
require 'simplecov-rcov'
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start 'rails'

That’s all done in your Rails project. Now you need to install two plugins in your Jenkins server:

Finally I have configured my metrics build as:

build-configuration

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>