Skip to content

Collect code coverage for rubygems and bundler#9394

Open
hsbt wants to merge 7 commits intomasterfrom
coverage
Open

Collect code coverage for rubygems and bundler#9394
hsbt wants to merge 7 commits intomasterfrom
coverage

Conversation

@hsbt
Copy link
Member

@hsbt hsbt commented Mar 13, 2026

Summary

The code for Rubygems and Bundler is quite old, so it's difficult to gauge whether a piece of code is still in use or needed. So I'm going to start by creating coverage using SimpleCov.

Usage

rake test              # generates rubygems coverage report
rake spec:regular      # generates bundler coverage report
rake test spec:regular # generates combined coverage report

Make sure the following tasks are checked

Copilot AI review requested due to automatic review settings March 13, 2026 02:49
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 introduces code coverage collection for the RubyGems (Test::Unit) and Bundler (RSpec) test suites using SimpleCov, and adds a rake task to collate results into a report under coverage/.

Changes:

  • Add simplecov as a development dependency for the Bundler dev bundle.
  • Start coverage collection from RubyGems tests and Bundler specs, and introduce an early-boot coverage preload for RubyGems.
  • Add a coverage:report rake task and automatically run it after rake test and rake spec:regular.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tool/bundler/dev_gems.rb Adds simplecov to the Bundler dev bundle dependencies.
test/rubygems/helper.rb Attempts to start SimpleCov during RubyGems test helper load.
test/rubygems/coverage_setup.rb New preload file to start coverage before requiring RubyGems.
bundler/spec/spec_helper.rb Attempts to start SimpleCov for the Bundler spec suite.
Rakefile Preloads coverage setup for rake test, adds coverage:report, and hooks report generation after test/spec tasks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +769 to +774
Rake::Task[:test].enhance do
Rake::Task["coverage:report"].reenable
Rake::Task["coverage:report"].invoke end
Rake::Task["spec:regular"].enhance do
Rake::Task["coverage:report"].reenable
Rake::Task["coverage:report"].invoke end
# of rubygems boot files. It must be used with --disable-gems and -Ilib
# so that Coverage.start runs before rubygems is loaded.

require "coverage"
begin
raise LoadError if ENV["GEM_COMMAND"]

gem "simplecov_json_formatter"
Comment on lines +43 to +52
begin
raise LoadError if File.exist?(File.expand_path("../../../lib/bundler/bundler.gemspec", __dir__))

gem "simplecov_json_formatter"
require "simplecov"

SimpleCov.start do
command_name "bundler:#{Process.pid}"
root File.expand_path("../..", __dir__)
coverage_dir File.expand_path("../../coverage", __dir__)
begin
raise LoadError if File.exist?(File.expand_path("../../../lib/bundler/bundler.gemspec", __dir__))

gem "simplecov_json_formatter"
Rakefile Outdated
Comment on lines +93 to +94
require "simplecov"
SimpleCov.collate Dir["coverage/.resultset.json"] do
hsbt and others added 6 commits March 13, 2026 12:08
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add coverage_setup.rb loaded via -r flag before rubygems to enable
Coverage tracking of boot files. SimpleCov is configured in helper.rb
to collect coverage data for rubygems test suite.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Configure SimpleCov in spec_helper.rb to collect coverage data for
the bundler test suite, outputting results to the shared coverage
directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When running bundler specs with parallel_rspec, each worker process
needs a unique command_name to prevent overwriting each other's
coverage results in .resultset.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add coverage:report task using SimpleCov.collate to merge results from
both test suites. Auto-run after test and spec:regular tasks. Add
convenience rake coverage task to run both suites.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Skip SimpleCov setup when running inside the ruby/ruby repository to
avoid interference. Detection uses GEM_COMMAND env var for rubygems
and bundler.gemspec presence for bundler.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Guard coverage:report task against missing SimpleCov or missing
resultset file so that rake test and spec:regular do not fail in
environments without SimpleCov installed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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