SimpleCov is a code coverage analysis tool for Ruby. It uses Ruby’s built-in Coverage library to gather code coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format, and display those results, giving you a complete code coverage suite that can be set up with just a couple lines of code.
Getting started
Add SimpleCov to your Gemfile and bundle install:
Load and launch SimpleCov at the very top of your spec_helper.rb (or test/test_helper.rb, cucumber env.rb, or whatever your preferred test framework uses):
12345678
require 'simplecov'
Spork.each_run do
if ENV['DRB']
require 'simplecov'
SimpleCov.start 'rails' if ENV["COVERAGE"]
end
end
Due to this code SimpleCov.start if ENV[“COVERAGE”] SimpleCov will only run if you execute your tests like this:
1
COVERAGE=true bundle exec rspec
Run your tests, open up coverage/index.html in your browser you can see detailed report on test coverage.