Skip to content

Commit 37be2fe

Browse files
richardboehmeandrykonchin
authored andcommitted
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.
1 parent 4770b42 commit 37be2fe

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

language/defined_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@
900900
defined?(DefinedSpecs::Undefined).should be_nil
901901
end
902902

903+
it "returns nil when the constant is not defined and the outer module implements .const_missing" do
904+
defined?(DefinedSpecs::ModuleWithConstMissing::Undefined).should be_nil
905+
end
906+
903907
it "does not call .const_missing if the constant is not defined" do
904908
DefinedSpecs.should_not_receive(:const_missing)
905909
defined?(DefinedSpecs::UnknownChild).should be_nil

language/fixtures/defined.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ def method_no_args
285285
end
286286
end
287287

288+
module ModuleWithConstMissing
289+
def self.const_missing(const)
290+
const
291+
end
292+
end
293+
288294
class SuperWithIntermediateModules
289295
include IntermediateModule1
290296
include IntermediateModule2

0 commit comments

Comments
 (0)