Skip to content

Commit

Permalink
Add spec for defined? on constant with const_missing
Browse files Browse the repository at this point in the history
Make sure that `defined?` returns nil even if `const_missing` is
implemented in the outer module.
  • Loading branch information
richardboehme committed Nov 10, 2024
1 parent bbcd077 commit ece2bf4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions language/defined_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@
defined?(DefinedSpecs::Undefined).should be_nil
end

it "returns nil when the constant is not defined and the outer module implements .const_missing" do
defined?(DefinedSpecs::ModuleWithConstMissing::Undefined).should be_nil
end

it "does not call .const_missing if the constant is not defined" do
DefinedSpecs.should_not_receive(:const_missing)
defined?(DefinedSpecs::UnknownChild).should be_nil
Expand Down
6 changes: 6 additions & 0 deletions language/fixtures/defined.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ def method_no_args
end
end

module ModuleWithConstMissing
def self.const_missing(const)
const
end
end

class SuperWithIntermediateModules
include IntermediateModule1
include IntermediateModule2
Expand Down

0 comments on commit ece2bf4

Please sign in to comment.