Skip to content

fix: set up Bundler under coverage only when the target has a bundle - #455

Open
TrapsterDK wants to merge 1 commit into
bazel-contrib:mainfrom
TrapsterDK:coverage-without-bundle
Open

TrapsterDK wants to merge 1 commit into
bazel-contrib:mainfrom
TrapsterDK:coverage-without-bundle

Conversation

@TrapsterDK

Copy link
Copy Markdown
Contributor

Sets up Bundler in the coverage helper only when the target has a bundle, so bazel coverage no longer fails for targets without one.

Without a bundle there is no BUNDLE_GEMFILE. require 'bundler/setup' then searches for a Gemfile and raises Bundler::GemfileNotFound (or Bundler::GemNotFound if it finds an unrelated one). The helper only rescued LoadError, so the test failed. Now Bundler is set up only when BUNDLE_GEMFILE is set, and a failure there prints a warning. The existing rescue LoadError still covers missing SimpleCov gems.

Fixes #453

Tested: adds a bundle-less rb_test (//spec:plain) to examples/gem and a CI step that runs bazel coverage //spec:plain. I could not run Bazel or Ruby locally, so this is only exercised by CI.

Assisted by Claude.

The coverage helper required bundler/setup unconditionally and rescued
only LoadError. A target without a bundle has no BUNDLE_GEMFILE, so
Bundler searched for a Gemfile and raised GemfileNotFound or
GemNotFound, which failed the test.

Set up Bundler only when BUNDLE_GEMFILE is set, and warn if that fails.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The coverage helper now sets up Bundler only when BUNDLE_GEMFILE is set. The gem example adds a test target without a Bundler dependency and runs it under coverage in CI.

Changes: Coverage for targets without Bundler

Layer / File(s) Summary
Conditional Bundler setup and coverage example
.github/workflows/ci.yml, examples/gem/spec/BUILD, examples/gem/spec/plain_test.rb, ruby/private/coverage/rules_ruby_coverage.rb
The coverage helper checks BUNDLE_GEMFILE before setting up Bundler. It warns on setup errors and continues to SimpleCov setup. The gem example defines a plain test target, and CI runs coverage for it.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant BazelCoverage
  participant RubyCoverageHelper
  participant Bundler
  participant SimpleCov
  BazelCoverage->>RubyCoverageHelper: Start coverage setup
  RubyCoverageHelper->>RubyCoverageHelper: Check BUNDLE_GEMFILE
  alt BUNDLE_GEMFILE is set
    RubyCoverageHelper->>Bundler: Require bundler/setup
  else BUNDLE_GEMFILE is unset
    RubyCoverageHelper->>RubyCoverageHelper: Skip Bundler setup
  end
  RubyCoverageHelper->>SimpleCov: Continue coverage setup
Loading

Suggested reviewers: noahkawasakigoogle, p0deje

Merge Risk: Minimal · up to 457b4

This change lets coverage runs succeed for tests that don't use Bundler, and it adds a CI check for that case. No merge-blocking risk was found. Bundler-backed targets keep their existing setup.

Architecture risk: Low · up to 457b4

The change affects 2 source areas.

Changed areas: examples, ruby

Review details

Systems and components

  • observed — 2 changed files mapped to examples.
  • observed — 1 changed file mapped to ruby.

Before / after behavior

  • observed — Modified behavior in examples/gem/spec/BUILD: Added the plain test target with plain_test.rb as its source and main program, and configured it as small with a moderate timeout.
  • observed — Modified behavior in examples/gem/spec/plain_test.rb: Added a Ruby script that enables frozen string literals, documents that it has no Bundler dependency, and prints ok.
  • observed — Modified behavior in ruby/private/coverage/rules_ruby_coverage.rb: Bundler setup is now conditional on BUNDLE_GEMFILE. Failures from StandardError or LoadError emit a warning; execution then continues to the SimpleCov setup.
  • observed — Modified behavior in ruby/private/coverage/rules_ruby_coverage.rb: Removed the unconditional Bundler setup require from the begin block that handles SimpleCov setup.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the coverage helper sets up Bundler only when the target has a bundle. The raw summary confirms the Ruby coverage helper now runs Bundler setup only when BUNDLE_GEMFIL…
Description check Passed The description states that Bundler setup in the coverage helper now runs only when the target has a bundle, so bazel coverage no longer fails for bundle-less targets. It also covers the new bundle-le…
Linked Issues check Passed Issue #453 requires that the coverage helper set up Bundler only when BUNDLE_GEMFILE is set, that a target without a bundle pass under coverage, and that a missing SimpleCov produce a warning and skip…
Out of Scope Changes check Passed All changes relate to #453. The helper change is the fix. The examples/gem/spec/BUILD plain rb_test, examples/gem/spec/plain_test.rb, and the .github/workflows/ci.yml step are regression coverage fo…
Full details: Title check

Explanation

The title names the main change: the coverage helper sets up Bundler only when the target has a bundle. The raw summary confirms the Ruby coverage helper now runs Bundler setup only when BUNDLE_GEMFILE is set. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description states that Bundler setup in the coverage helper now runs only when the target has a bundle, so bazel coverage no longer fails for bundle-less targets. It also covers the new bundle-less rb_test (//spec:plain) and the CI step, which match the raw summary. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Issue #453 requires that the coverage helper set up Bundler only when BUNDLE_GEMFILE is set, that a target without a bundle pass under coverage, and that a missing SimpleCov produce a warning and skip coverage. At the reviewed head, ruby/private/coverage/rules_ruby_coverage.rb wraps require 'bundler/setup' in if ENV['BUNDLE_GEMFILE']. It rescues StandardError, LoadError and prints a warning. Bundler::GemfileNotFound and Bundler::GemNotFound are covered by StandardError. The SimpleCov block keeps its rescue LoadError and warns that simplecov or simplecov-lcov is missing, so coverage is skipped without failing the test. The Bundler require is no longer inside the SimpleCov begin block. The bundle-less reproduction target //spec:plain is added to examples/gem/spec/BUILD and a CI step runs bazel coverage //spec:plain. This matches the reproduction in the issue. I did not run Bazel or Ruby. Behavior is established from the source read at head and the PR summary.

Full details: Out of Scope Changes check

Explanation

All changes relate to #453. The helper change is the fix. The examples/gem/spec/BUILD plain rb_test, examples/gem/spec/plain_test.rb, and the .github/workflows/ci.yml step are regression coverage for the fix. They do not add unrelated behavior. The change set in the PR summary has no other files. The ci.yml and BUILD changes were confirmed from the PR summary only, not from a file read.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: c4aeb98f-8bb3-49fd-965f-58507f8a3482
Commits

Reviewing files that changed from the base of the PR and between 81a3c0a and 457b4ff.

Files selected for processing: 4

  • .github/workflows/ci.yml
  • examples/gem/spec/BUILD
  • examples/gem/spec/plain_test.rb
  • ruby/private/coverage/rules_ruby_coverage.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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.

Coverage fails for targets without a Bundler dependency

1 participant