diff options
author | Jean Boussier <[email protected]> | 2022-06-18 10:29:52 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2022-06-18 14:49:02 +0200 |
commit | eca31d24d606a73def3674938112dc3c5b79c445 (patch) | |
tree | aa713097baa398f55af41319f6fe1d5c2c583730 /spec/ruby/core | |
parent | e7117115399981e1258ca6301e76cc3a24c509e7 (diff) |
[Bug #18813] Warn when autoload has to lookup in parent namespace
This is a verbose mode only warning.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6038
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/module/autoload_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index 7e7e7a2139..af04ab26c8 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -577,6 +577,36 @@ describe "Module#autoload" do end end + ruby_version_is "3.2" do + it "warns once in verbose mode if the constant was defined in a parent scope" do + ScratchPad.record -> { + ModuleSpecs::DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent + } + + module ModuleSpecs + module Autoload + autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb") + self.autoload?(:DeclaredInCurrentDefinedInParent).should == fixture(__FILE__, "autoload_callback.rb") + const_defined?(:DeclaredInCurrentDefinedInParent).should == true + + -> { + DeclaredInCurrentDefinedInParent + }.should complain( + /Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/, + verbose: true, + ) + + -> { + DeclaredInCurrentDefinedInParent + }.should_not complain(/.*/, verbose: true) + self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil + const_defined?(:DeclaredInCurrentDefinedInParent).should == false + ModuleSpecs.const_defined?(:DeclaredInCurrentDefinedInParent).should == true + end + end + end + end + ruby_version_is "3.1" do it "looks up in parent scope after failed autoload" do @remove << :DeclaredInCurrentDefinedInParent |