Documentation
Ruby test coverage
Set up Supercov with your agent, or run it yourself with RSpec, Minitest or Rails tests.
Ask your coding agent to set up Supercov in your project:
Install the supercov gem in this project's Ruby environment. Read
supercov docs and run our existing tests with the project's bundle.
Follow supercov docs assertion-agent to build and validate the assertion map.
Show the coverage report and any measurement limits. Don't change
application code or tests.Run it yourself
Use Ruby 3.4 or newer for full measurement. Ruby 3.3 provides line, method and simple-branch coverage, but not the full MC/DC measurement shown below.
Install Supercov in the Ruby environment you use for your project:
gem install supercov
supercov --version
The gem includes the CLI; you don’t need Node.js. Your test runner and project dependencies still need to be installed.
Run your tests
For an RSpec project:
supercov -- bundle exec rspec
For Rails or Minitest, wrap the command you already use instead:
supercov -- bin/rails test
supercov -- ruby -Itest test/test_session.rb
Replace the Minitest filename with your test file, or use supercov -- rake test
for the full suite. Supercov runs Ruby in your project directory with your
bundle. It uses RUBYOPT to load its hooks without rewriting application files.
It tracks individual tests in RSpec, Minitest and test-unit, and scenarios in Cucumber.
Inspect the result:
supercov runs latest
supercov runs latest gaps --limit 5Try a small example
Download the examples, extract them,
and open supercov-examples/ruby. The tests use Minitest. If it isn’t available
in this Ruby environment, install it with gem install minitest.
The lib/session.rb file contains:
def checkout(signed_in, expired, price, quantity)
if signed_in && !expired
total = price * quantity
return { status: 'confirmed', total: total }
end
{ status: 'denied', total: 0 }
end
Its two tests check a valid order and a signed-out visitor. Run them from the example folder:
supercov -- ruby -Itest test/test_session.rb
supercov runs latest
The coverage section recorded with Supercov 0.0.48 is:
Coverage
Lines 100.00% (5/5)
Branches 100.00% (6/6)
MC/DC 50.00% (1/2)
Both branches ran, but the expiry check hasn’t been tested independently:
supercov runs latest decision lib/session.rb:2
The report includes:
signed_in && !expired
C1 covered: signed_in
C2 MISSING: !expired
A test for a signed-in customer with an expired session closes that gap. The recorded run reaches 100% MC/DC after adding it; MC/DC explains the measurement.
Check what the tests assert
These tests check the status, not order[:total]. Adding
assert_equal 50, order[:total] would check the calculation for this input.
The setup prompt asks your agent to map assertions to the code they check. Supercov checks the map against the recorded tests. A normal run alone doesn’t produce that assessment. See Assertion coverage.
Ruby-specific limits
A Spring preloader started before Supercov won’t have its measurement hook; restart it inside the measured command. JRuby and TruffleRuby aren’t supported. Forked Rails workers are supported. When tests run in overlapping threads, some execution can only be assigned to the whole suite. See runner support for details.
Already using SimpleCov? See how the reports differ.
supercov docs coverage-model prints the guide for your installed version.