Add SimpleCov Code Coverage Support#137
Merged
fractaledmind merged 23 commits intomainfrom Jan 23, 2026
Merged
Conversation
Ensure SimpleCov is required early in the Rails binstub so coverage tracking is initialized before any gem code is loaded.
SimpleCov is now started in test/dummy/config/boot.rb
- Start SimpleCov in boot.rb before gems load (when COVERAGE=1) - Run tests serially when COVERAGE=1 for accurate tracking - Run tests in parallel by default for speed - Configure SimpleCov with branch coverage and proper filters
- Test matrix runs in parallel without coverage (fast) - Separate coverage job runs with COVERAGE=1 and uploads report
- Add minimum coverage thresholds to .simplecov (80% line, 70% branch) - Add per-file minimums (50% line, 40% branch) - Only enforce thresholds when COVERAGE_CHECK=1 to avoid failing during db operations - Update CI coverage job to set COVERAGE_CHECK=1 - Update Rakefile to unset COVERAGE_CHECK during db:sync - Document COVERAGE_CHECK in README
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds SimpleCov code coverage support to the test suite with an opt-in approach that maintains fast parallel test runs by default and provides accurate serial coverage tracking when explicitly requested.
Changes:
- SimpleCov configuration with branch coverage enabled via
.simplecovfile - Conditional coverage collection triggered by
COVERAGE=1environment variable - Serial test execution when coverage is enabled, parallel execution otherwise
- New CI workflow job for coverage report generation
- Updated documentation with coverage usage instructions
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.simplecov |
SimpleCov configuration with branch coverage, filters, and formatters |
test/dummy/config/boot.rb |
Initializes SimpleCov before loading gems when COVERAGE=1 |
test/test_helper.rb |
Conditionally runs tests serially (coverage) or parallel (normal) |
Rakefile |
Passes COVERAGE environment variable through to test commands |
.gitignore |
Ignores coverage directories at root and in test dummy app |
README.md |
Documents test execution options including coverage generation |
.github/workflows/ci.yml |
Adds dedicated coverage job and improves artifact naming |
Gemfile.lock |
Adds SimpleCov dependencies (mysql2 version bump is incidental) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Move bundler/setup before SimpleCov.start so that gem dependencies like minitest/mock are available when SimpleCov initializes.
- Move SimpleCov.start from boot.rb to test_helper.rb so it only runs during test execution, not during db:setup or other rake tasks - Exclude Ruby 3.2 from rails_main matrix (requires Ruby >= 3.3) - Update .simplecov comment to reflect new location
- Move SimpleCov.start to bin/rails, before Rails/gem code loads - Only start SimpleCov when running 'bin/rails test', not other commands - Disable parallelization entirely (not just workers: 1) when COVERAGE=1 This ensures all gem code is tracked for coverage (70%+ line coverage) while avoiding SimpleCov running during db:setup or other rake tasks.
Explicitly require 'minitest' before 'minitest/mock' to ensure the bundled gem is properly loaded. In Ruby 3.2+, minitest is a bundled gem that may not be automatically available unless explicitly required.
Minitest 6.0 (released Dec 2025) removed minitest/mock.rb and moved it to a separate minitest-mock gem. This caused LoadError in CI when bundler resolved to minitest 6.x. Pin minitest to < 6 in all gemfiles until the ecosystem stabilizes around this breaking change.
Line: 80% -> 70% Branch: 70% -> 40% Per-file branch: 40% -> 30%
Some files have low coverage that can be improved later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds SimpleCov code coverage support to the test suite with an opt-in approach that keeps normal test runs fast.
Usage
Normal test runs (fast, parallel):
bundle exec rake test:sqliteWith coverage reporting (serial, accurate):
COVERAGE=1 bundle exec rake test:sqliteThe HTML coverage report is generated in the
coverage/directory.How it works
COVERAGE=1enables SimpleCov and runs tests serially for accurate coverage trackingCOVERAGEtests run in parallel with no coverage overheadtest/dummy/config/boot.rbbefore any gems are loaded, ensuring all gem code is trackedCI Integration
coveragejob runs withCOVERAGE=1and uploads the HTML report as an artifactChanges
.simplecov)test/dummy/config/boot.rbwhenCOVERAGE=1COVERAGE=1, parallel otherwiseCOVERAGEenv var through rake tasksrake testbehavior to run against all databasesenqueuing_job_test.rb