Skip to content

Add SimpleCov Code Coverage Support#137

Merged
fractaledmind merged 23 commits intomainfrom
simplecov
Jan 23, 2026
Merged

Add SimpleCov Code Coverage Support#137
fractaledmind merged 23 commits intomainfrom
simplecov

Conversation

@fractaledmind
Copy link
Owner

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:sqlite

With coverage reporting (serial, accurate):

COVERAGE=1 bundle exec rake test:sqlite

The HTML coverage report is generated in the coverage/ directory.

How it works

  • COVERAGE=1 enables SimpleCov and runs tests serially for accurate coverage tracking
  • Without COVERAGE tests run in parallel with no coverage overhead
  • SimpleCov is started in test/dummy/config/boot.rb before any gems are loaded, ensuring all gem code is tracked
  • Branch coverage is enabled by default

CI Integration

  • The test matrix continues to run in parallel without coverage (fast feedback)
  • A separate coverage job runs with COVERAGE=1 and uploads the HTML report as an artifact

Changes

  • Add SimpleCov configuration (.simplecov)
  • Start SimpleCov in test/dummy/config/boot.rb when COVERAGE=1
  • Run tests serially when COVERAGE=1, parallel otherwise
  • Pass COVERAGE env var through rake tasks
  • Add coverage job to CI workflow
  • Update README with test running instructions
  • Restore rake test behavior to run against all databases
  • Uncomment tests in enqueuing_job_test.rb

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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .simplecov file
  • Conditional coverage collection triggered by COVERAGE=1 environment 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.

fractaledmind and others added 11 commits January 22, 2026 20:55
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.
@fractaledmind fractaledmind merged commit 156533b into main Jan 23, 2026
87 of 88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants