Simplecov
Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
Install / Use
/learn @simplecov-ruby/SimplecovREADME
SimpleCov

Code coverage for Ruby
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. SimpleCov/Coverage track covered ruby code, gathering coverage for common templating solutions like erb, slim and haml is not supported.
In most cases, you'll want overall coverage results for your projects, including all types of tests, Cucumber features, etc. SimpleCov automatically takes care of this by caching and merging results when generating reports, so your report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
The official formatter of SimpleCov is packaged as a separate gem called simplecov-html, but will be installed and configured automatically when you launch SimpleCov. If you're curious, you can find it on GitHub, too.
Contact
Code and Bug Reports
- Issue Tracker
- See CONTRIBUTING for how to contribute along with some common problems to check out before creating an issue.
Questions, Problems, Suggestions, etc.
- Mailing List "Open mailing list for discussion and announcements on Google Groups"
Getting started
-
Add SimpleCov to your
Gemfileandbundle install:gem 'simplecov', require: false, group: :test -
Load and launch SimpleCov at the very top of your
test/test_helper.rb(orspec_helper.rb,rails_helper, cucumberenv.rb, or whatever your preferred test framework uses):require 'simplecov' SimpleCov.start # Previous content of test helper now starts hereNote: If SimpleCov starts after your application code is already loaded (via
require), it won't be able to track your files and their coverage! TheSimpleCov.startmust be issued before any of your application code is required!This is especially true if you use anything that keeps your tests application loaded like spring, check out the spring section.
SimpleCov must be running in the process that you want the code coverage analysis to happen on. When testing a server process (e.g. a JSON API endpoint) via a separate test process (e.g. when using Selenium) where you want to see all code executed by the
rails server, and not just code executed in your actual test files, you need to require SimpleCov in the server process. For rails for instance, you'll want to add something like this to the top ofbin/rails, but below the "shebang" line (#! /usr/bin/env ruby) and after config/boot is required:if ENV['RAILS_ENV'] == 'test' require 'simplecov' SimpleCov.start 'rails' puts "required simplecov" end -
Run your full test suite to see the percent coverage that your application has.
-
After running your tests, open
coverage/index.htmlin the browser of your choice. For example, in a Mac Terminal, run the following command from your application's root directory:open coverage/index.htmlin a debian/ubuntu Terminal,
xdg-open coverage/index.htmlNote: This guide can help if you're unsure which command your particular operating system requires.
-
Add the following to your
.gitignorefile to ensure that coverage results are not tracked by Git (optional):echo coverage >> .gitignoreIf you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on profiles) that will get you started with groups for your Controllers, Models and Helpers. To use it, the first two lines of your test_helper should be like this:
require 'simplecov' SimpleCov.start 'rails'
Example output
Coverage results report, fully browsable locally with sorting and much more:

Source file coverage details view:

Use it with any framework!
Similarly to the usage with Test::Unit described above, the only thing you have to do is to add the SimpleCov config to the very top of your Cucumber/RSpec/whatever setup file.
Add the setup code to the top of features/support/env.rb (for Cucumber) or spec/spec_helper.rb (for RSpec).
Other test frameworks should work accordingly, whatever their setup file may be:
require 'simplecov'
SimpleCov.start 'rails'
You could even track what kind of code your UI testers are touching if you want to go overboard with things. SimpleCov does not care what kind of framework it is running in; it just looks at what code is being executed and generates a report about it.
Notes on specific frameworks and test utilities
For some frameworks and testing tools there are quirks and problems you might want to know about if you want to use SimpleCov with them. Here's an overview of the known ones:
<table> <tr><th>Framework</th><th>Notes</th><th>Issue</th></tr> <tr> <th> parallel_tests </th> <td> As of 0.8.0, SimpleCov should correctly recognize parallel_tests and supplement your test suite names with their corresponding test env numbers. SimpleCov locks the resultset cache while merging, ensuring no race conditions occur when results are merged. </td> <td> <a href="https://github.com/simplecov-ruby/simplecov/issues/64">#64</a> & <a href="https://github.com/simplecov-ruby/simplecov/pull/185">#185</a> </td> </tr> <tr> <th> knapsack_pro </th> <td> To make SimpleCov work with Knapsack Pro Queue Mode to split tests in parallel on CI jobs you need to provide CI node index number to the <code>SimpleCov.command_name</code> in <code>KnapsackPro::Hooks::Queue.before_queue</code> hook. </td> <td> <a href="https://knapsackpro.com/faq/question/how-to-use-simplecov-in-queue-mode">Tip</a> </td> </tr> <tr> <th> RubyMine </th> <td> The <a href="https://www.jetbrains.com/ruby/">RubyMine IDE</a> has built-in support for SimpleCov's coverage reports, though you might need to explicitly set the output root using `SimpleCov.root('foo/bar/baz')` </td> <td> <a href="https://github.com/simplecov-ruby/simplecov/issues/95">#95</a> </td> </tr> <tr> <th> Spork </th> <td> Because of how Spork works internally (using preforking), there used to be trouble when using SimpleCov with it, but that has apparently been resolved with a specific configuration strategy. See <a href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">this</a> comment. </td> <td> <a href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">#42</a> </td> </tr> <tr> <th> Spring </th> <td> <a href="#want-to-use-spring-with-simplecov">See section below.</a> </td> <td> <a href="https://github.com/simplecov-ruby/simplecov/issues/381">#381</a> </td> </tr> <tr> <th> Test/Unit </th> <td> Test Unit 2 used to mess with ARGV, leading to a failure to detect the test process name in SimpleCov. <code>test-unit</code> releases 2.4.3+ (Dec 11th, 2011) should have this problem resolved. </td> <td> <a href="https://github.com/simplecov-ruby/simplecov/issues/45">#45</a> & <a href="https://github.com/test-unit/test-unit/pull/12">test-unit/test-unit#12</a> </td> </tr> </table>Configuring SimpleCov
Configuration settings can be applied in three
Related Skills
node-connect
333.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
333.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.0kCommit, push, and open a PR
