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:
- Simplecov: This analyses the coverture of your tests (rspec and minitest)
- Rubocop: Hints the code style when not respect the community guidelines
- Rspec: Yes, besides testing functionality, it provides a report option that I like to include in my Jenkins builds.
- Rails Best Practices: warns about bad smells based on best practices discussed by the Rails community
- MetricFu: summarizes these and others tools for deeper analysis
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:
- Ruby Metrics Plugin: which publishes Simplecov reports
- HTML Publisher Plugin: which we will use to publish the other reports
Finally I have configured my metrics build as: