From ece2bf4435ec4efb8cc1623a1a86b12563292566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20B=C3=B6hme?= Date: Fri, 8 Nov 2024 16:40:29 +0100 Subject: [PATCH] Add spec for `defined?` on constant with const_missing Make sure that `defined?` returns nil even if `const_missing` is implemented in the outer module. --- language/defined_spec.rb | 4 ++++ language/fixtures/defined.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/language/defined_spec.rb b/language/defined_spec.rb index 34408c0190..80ad1818b1 100644 --- a/language/defined_spec.rb +++ b/language/defined_spec.rb @@ -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 diff --git a/language/fixtures/defined.rb b/language/fixtures/defined.rb index a9552619bf..3761cfa5bd 100644 --- a/language/fixtures/defined.rb +++ b/language/fixtures/defined.rb @@ -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