Repository navigation
Add test coverage for NameError#missing_name branches - #58325
Merged
byroot merged 1 commit intoAug 1, 2026
Merged
Conversation
`NameError#missing_name` has four code paths depending on the exception's receiver, but only the namespaced one (`receiver` is a module other than `Object`) and the early return for non-constant errors were covered. Adds coverage for: * A missing top-level constant, where `receiver` is `Object` and the name is returned unqualified. This is the example given in the method's own documentation. * An exception with no receiver, where `#receiver` raises `ArgumentError` and the name is recovered from the message instead. * `missing_name?` returning false for a message that is not about an uninitialized constant. This brings `active_support/core_ext/name_error.rb` to full line coverage.
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.
Summary
NameError#missing_namebranches on the exception's receiver:Of these, only the
elsif receiverbranch and the early return for non-constant errors were exercised. Line coverage overactivesupport/test/core_ext/showed thereceiver == Objectbranch, therescue ArgumentErrorbranch, and the message-matching fallback all unreached.Notably the
receiver == Objectcase is the example in the method's own documentation:Tests added
test_missing_top_level_constant_is_not_namespaced— a missing top-level constant hasObjectas its receiver and returns the name unqualified, matching the documented example.test_missing_name_falls_back_to_the_message_without_a_receiver— aNameErrorbuilt without a receiver raisesArgumentErrorfrom#receiver, so the name is recovered from the message.test_missing_name_ignores_a_message_that_is_not_about_a_constant—missing_nameisnilandmissing_name?is false for a non-constant message.No behavior changes — tests only, so no CHANGELOG entry.
active_support/core_ext/name_error.rbgoes from 17/21 to full line coverage.activesupport/test/core_ext/: 1474 runs, 6124 assertions, 0 failures, 0 errors. RuboCop clean.