SimpleCov "Line coverage is below the expected minimum" in CI
SimpleCov enforces minimum_coverage at the end of the test run. When line (or branch) coverage is below the set minimum, it prints the shortfall and sets a non-zero exit status, failing the CI job.
What this error means
After RSpec/Minitest finishes, SimpleCov prints "SimpleCov failed with exit 2 due to a coverage related error" and "Line coverage (72.5%) is below the expected minimum coverage (80.00%)."
Coverage report generated for RSpec to /app/coverage. 72.5% covered.
Line coverage (72.5%) is below the expected minimum coverage (80.00%).
SimpleCov failed with exit 2 due to a coverage related error.Common causes
Coverage fell below minimum_coverage
New untested code lowered line or branch coverage under the value configured in the SimpleCov block.
Parallel or multi-suite runs not merged
Split test suites each write partial results; without merging, the measured percentage is lower than the true total and trips the gate.
How to fix it
Add tests or set a realistic minimum
- Open
coverage/index.htmlto find the uncovered files and lines. - Add tests for the gaps.
- If the bar is too high for now, set
minimum_coverageto the honest current level and raise it over time.
# spec/spec_helper.rb
require 'simplecov'
SimpleCov.start do
minimum_coverage line: 80, branch: 70
endMerge results from split suites
Use a shared command_name per suite and let SimpleCov merge results so the total is computed across all of them.
SimpleCov.start do
command_name "Job#{ENV['CI_NODE_INDEX']}"
endHow to prevent it
- Run the suite with SimpleCov locally before pushing.
- Merge coverage from parallel jobs before evaluating the minimum.
- Raise
minimum_coverageincrementally as coverage improves.