Improve branch test coverage - #2897
Merged
Merged
Conversation
Danger ReportNo issues found. |
dblock
force-pushed
the
improve-branch-coverage
branch
from
September 4, 2026 12:37
89fa6b8 to
a7c1016
Compare
dblock
force-pushed
the
improve-branch-coverage
branch
3 times, most recently
from
September 5, 2026 21:31
b4af65c to
9b3c3c1
Compare
Add specs for previously-untested classes/methods and branches across the middleware, router, serve_stream, util, validations and exceptions namespaces. Also remove a structurally unreachable "format not supported" throw in Grape::Middleware::Error#format_message: formatter_for always falls back to a registered Txt formatter (registered via ErrorFormatter::Base.inherited), so `formatter` can never be falsy and the 406 branch could never execute. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dblock
force-pushed
the
improve-branch-coverage
branch
from
September 5, 2026 21:33
9b3c3c1 to
81dd073
Compare
…d translation utilities Adds direct unit tests to exercise previously-uncovered branches: - Grape::Exceptions::Base#translate_message (Proc/Hash-pattern/plain-value branches, and the Hash-without-:key error case) - Grape::Exceptions::RequestError (new spec file) - Grape::Exceptions::Validation (message omitted case) - Grape::Middleware::Base (instance-level #default_options fallback) - Grape::Middleware::Error (#resolved_backtrace fallback chain, InvalidVersionHeader precedence) - Grape::Middleware::Stack::Middleware#== (non-Middleware/non-Class comparison) - Grape::Middleware::Versioner::Header (skips media-type matching without a vendor) - Grape::Namespace.joined_space - Grape::Router::BaseRoute#initialize (ActiveSupport::OrderedOptions wrapping) - Grape::Router::MustermannPattern (:param capture syntax, Integer vs. default constraint) - Grape::Router::Pattern::Path#suffix (non-path versioning) - Grape::Testing (missing block / no registered hooks) - Grape::Util::Translation#translate (explicit locale / explicit default / fallback-locale retry) Also marks one genuinely unreachable branch (comment-only, not deleted, per project convention): - Grape::DSL::Routing#version's trailing `@versions&.last` — @versions is unconditionally reassigned to an Array a few lines above, so the `&.` can never see nil. Raises the full-matrix branch coverage from 95.58% (1278/1337) to 96.85% (1324/1367), while keeping line coverage at 100%. Not aiming for 100% branch coverage; only the easy, high-signal gaps were closed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dblock
force-pushed
the
improve-branch-coverage
branch
from
September 5, 2026 21:37
81dd073 to
7d49331
Compare
ericproulx
approved these changes
Sep 6, 2026
ericproulx
approved these changes
Sep 6, 2026
2 tasks
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.
What
Stacked on top of #2896 (which brings line coverage to 100%). This PR
improves branch coverage where it was easy to do, without chasing
100%.
Method: ran the full CI-equivalent test matrix (main suite + all
integration/rack/rails Gemfile variants) and used
SimpleCov.collateto get the true combined coverage, then added direct unit tests for
previously-uncovered branches that were easy/cheap to reach:
Grape::Exceptions::Base#translate_message— the Proc, Hash-pattern-match, plain-value, and Hash-without-:keybranches.Grape::Exceptions::RequestError— no spec file existed; added one.Grape::Exceptions::Validation— the "message omitted" default branch.Grape::Middleware::Base— the instance-level#default_optionsfallback (for middleware subclasses outside this repo, e.g. 3rd-party gems).Grape::Middleware::Error—#resolved_backtrace's fallback chain, and theInvalidVersionHeaderprecedence-handler branch.Grape::Middleware::Stack::Middleware#==— comparison against something that's neither aMiddlewarenor aClass.Grape::Middleware::Versioner::Header— skips the best-quality media-type match entirely when no vendor is configured.Grape::Namespace.joined_space.Grape::Router::BaseRoute#initialize— theActiveSupport::OrderedOptionswrapping branch.Grape::Router::MustermannPattern— the:namecapture syntax (no spec previously exercised it at all), both theInteger-constrained and default-constraint cases.Grape::Router::Pattern::Path#suffix— the non-path (e.g. header) versioning branch.Grape::Testing— missing-block and no-registered-hooks branches.Grape::Util::Translation#translate— explicitlocale:, explicitdefault:, the no-default-given case, and the fallback-locale retry path.Two branches (
Grape::DSL::Routing#version's trailing@versions&.last,and
Grape::Util::Translation#translate'seffective_defaultcomputationwhen the caller's
default:isn'tMISSING) looked unreachable, but per#2904's finding that a similarly-reasoned "unreachable" branch in
Route#tag_utf8!turned out to be reachable after all, nosimplecov:disablemarkers were added for them here — they're left as genuinely uncovered
rather than asserted dead, so a future contributor (or SimpleCov's report)
can still flag them if that reasoning turns out to be wrong too.
Result
Full-matrix branch coverage: 95.58% (1278/1337) → ~96.8% (up from the
session-start baseline; exact combined number depends on which
integration/rack/rails Gemfile variants are included in the collate run).
Line coverage stays at 100%. Remaining uncovered branches are mostly
in validators/type coercion code that would need much more elaborate
setup to exercise, so they were left alone per "don't aim for 100%".
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com