Skip to content

Expand matcher behavior coverage to 99.56% with combined Mongoid 6/9 CI reporting - #263

Merged
dblock merged 1 commit into
mongoid:masterfrom
dblock:dblock/coverage
Oct 18, 2026
Merged

dblock merged 1 commit into
mongoid:masterfrom
dblock:dblock/coverage

Conversation

@dblock

@dblock dblock commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Exercise storage matcher specs in the default Rake suite (the existing file lacked the _spec.rb suffix).
  • Add meaningful public matcher behavior and failure-diagnostic assertions for associations, validators, fields, documents, timestamps, indexes, nested attributes, and command normalization.
  • Test historical Rails mass-assignment and Mongoid 3 index contracts with explicitly isolated compatibility doubles; validate association compatibility against real Mongoid 6.
  • Load the standalone version entry point with its constant hidden, verifying the actual definition and safely removing it before RSpec restores the original.
  • Persistently report genuine Mongoid 6 and 9 CI coverage with parallel Coveralls flags and finalize only after the full test matrix succeeds.
  • Allow MONGODB_URI in the unit test harness and document database purging/isolation.

No production behavior changes, coverage exclusions, nocov, or tracked-file reductions.

Coverage audit

Fresh upstream master baseline at fc3e355c2ec1f06e82d796c8308970563b8f3a98:

Run Examples Covered / relevant lines Line coverage
Before: Ruby 3.3.5 / Mongoid 9.0.12 208 945 / 1165 81.1159%
After: Ruby 3.3.5 / Mongoid 9.0.12 256 1123 / 1146 97.9930%
After: Ruby 2.7.7 / Mongoid 6.0.3 258 1131 / 1146 98.6911%
Union of those two genuine full-suite runs — 1141 / 1146 99.5637%

All 29 library files remain tracked. The 19-line denominator difference comes from executing/parsing the previously unloaded legacy index implementation and preloaded version entry point rather than SimpleCov's unloaded-file approximation; no source lines were removed or filtered.

The modern run still misses old association constants/metadata, ordering/counter-cache compatibility paths; the real legacy run covers those. The combined remaining 5 lines are:

  • lib/mongoid/rspec.rb:39: Mongoid 3 loader branch (the current supported CI matrix begins at Mongoid 4; its index implementation is separately exercised).
  • lib/matchers/allow_mass_assignment.rb:63: unused private accessible_attributes helper, unreachable through the public matcher.
  • lib/matchers/validations.rb:116-117: redundant context-mismatch path after the same condition already filtered the validator.
  • lib/matchers/be_stored_in.rb:43: defensive rescue for a dynamic storage value; modern Mongoid normalizes/rejects that value before the matcher receives it.

These gaps remain visible rather than being hidden. This is line coverage, not a claim of complete branch coverage; existing instrumentation does not measure branches.

Accepted CI coverage

Coveralls build 82425438 accepted 99.5641% (1142/1147 lines; 5 missed) for final PR head 4184388dcef928911bc115c5b31c6f30b5e3115a (GitHub PR merge SHA fe2f6531b6f52f1aeb2010e6df602f911c3bf93b).

This is the finalized server-side union, not only a local calculation: the supported Mongoid 6 / Ruby 2.7 job and Mongoid 9 / Ruby 3.4 job upload flags mongoid_6 and mongoid_9 through the official Coveralls action with parallel: true. A dependent job sends parallel-finished: true only after the complete test matrix succeeds. The CI runtime's relevant-line count differs by one from the local Ruby 3.3/2.7 measurement; both retain the same five missed lines.

All 15 current-head checks passed, including all 11 Ruby/Mongoid matrix jobs, integration, lint, Danger, and coverage finalization: final Test run.

Validation

COVERAGE=true BUNDLE_GEMFILE=gemfiles/mongoid_9.gemfile \
  MONGODB_URI=mongodb://localhost:27040/mongoid_rspec_coverage bundle exec rake
COVERAGE=true BUNDLE_GEMFILE=gemfiles/mongoid_6.gemfile \
  MONGODB_URI=mongodb://localhost:27040/mongoid_rspec_coverage_legacy bundle exec rake
BUNDLE_GEMFILE=gemfiles/shoulda_matchers.gemfile \
  bundle exec rspec spec/integration/shoulda_matchers
COVERAGE=true BUNDLE_GEMFILE=gemfiles/mongoid_9.gemfile bundle exec rubocop

Both full unit suites pass; shoulda-matchers integration: 10 examples, 0 failures; RuboCop: 77 files, no offenses. MongoDB tests used dedicated databases on the existing MongoDB server; no shared application/test database was purged.

The storage fixtures use Mongoid 4's session option and Mongoid 5+'s client option; dynamic storage assertions run on Mongoid 6+, where the production matcher’s persistence_context API exists.

Posted by GitHub Copilot (AI) on behalf of @dblock.

Update: version tests now assert the already-loaded public constant directly. Removed constant hiding/replacement, version-file reloading, and manual cleanup used only to count assignments under coverage. Any coverage decrease is intentional; earlier percentages above predate this simplification. Genuine compatibility and integration tests remain unchanged.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@dblock
dblock force-pushed the dblock/coverage branch 2 times, most recently from 510ac4a to 60abe75 Compare October 17, 2026 12:20
@dblock dblock changed the title Expand matcher behavior coverage to 97.56% (99.13% across Mongoid 6/9) Expand matcher behavior coverage to 97.99% (99.56% across Mongoid 6/9) Oct 17, 2026
@dblock dblock changed the title Expand matcher behavior coverage to 97.99% (99.56% across Mongoid 6/9) Expand matcher behavior coverage to 99.56% with combined Mongoid 6/9 CI reporting Oct 17, 2026
@dblock
dblock force-pushed the dblock/coverage branch 2 times, most recently from 77ab569 to 55a69d7 Compare October 18, 2026 13:32
Exercise storage specs in the default suite, cover matcher failures and historical compatibility contracts, and document isolated MongoDB test databases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dblock
dblock merged commit c3a765f into mongoid:master Oct 18, 2026
15 checks passed
@dblock
dblock deleted the dblock/coverage branch October 18, 2026 13:57
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.

1 participant