@@ -568,10 +568,17 @@ class LexicalScope
568
568
LexicalScope ::DeclaredInParentDefinedInCurrent . should == :declared_in_parent_defined_in_current
569
569
end
570
570
571
- # Basically, the parent autoload constant remains in a "undefined" state
572
571
self . autoload? ( :DeclaredInParentDefinedInCurrent ) . should == nil
573
572
const_defined? ( :DeclaredInParentDefinedInCurrent ) . should == false
574
573
-> { DeclaredInParentDefinedInCurrent } . should raise_error ( NameError )
574
+ ruby_version_is "" ..."3.1" do
575
+ # Basically, the parent autoload constant remains in a "undefined" state
576
+ self . should have_constant ( :DeclaredInParentDefinedInCurrent )
577
+ end
578
+ ruby_version_is "3.1" do
579
+ # The autoload constant has been removed
580
+ self . should_not have_constant ( :DeclaredInParentDefinedInCurrent )
581
+ end
575
582
576
583
ModuleSpecs ::Autoload ::LexicalScope . send ( :remove_const , :DeclaredInParentDefinedInCurrent )
577
584
end
@@ -592,13 +599,11 @@ module Autoload
592
599
-> {
593
600
DeclaredInCurrentDefinedInParent
594
601
} . should complain (
595
- /Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/ ,
596
- verbose : true ,
597
- )
602
+ /Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/ , verbose : true )
598
603
599
604
-> {
600
605
DeclaredInCurrentDefinedInParent
601
- } . should_not complain ( /.*/ , verbose : true )
606
+ } . should_not complain ( verbose : true )
602
607
self . autoload? ( :DeclaredInCurrentDefinedInParent ) . should == nil
603
608
const_defined? ( :DeclaredInCurrentDefinedInParent ) . should == false
604
609
ModuleSpecs . const_defined? ( :DeclaredInCurrentDefinedInParent ) . should == true
@@ -607,8 +612,9 @@ module Autoload
607
612
end
608
613
end
609
614
615
+ # like net/https used to do `module Net; autoload :OpenSSL, 'openssl'; end` before https://github.com/ruby/net-http/commit/369c3fd708
610
616
ruby_version_is "3.1" do
611
- it "looks up in parent scope after failed autoload " do
617
+ it "looks up in parent scope when declared in current and defined in parent " do
612
618
@remove << :DeclaredInCurrentDefinedInParent
613
619
module ModuleSpecs ::Autoload
614
620
ScratchPad . record -> {
@@ -617,10 +623,11 @@ module ModuleSpecs::Autoload
617
623
618
624
class LexicalScope
619
625
autoload :DeclaredInCurrentDefinedInParent , fixture ( __FILE__ , "autoload_callback.rb" )
620
- -> { DeclaredInCurrentDefinedInParent } . should_not raise_error ( NameError )
621
- # Basically, the autoload constant remains in a "undefined" state
626
+ DeclaredInCurrentDefinedInParent . should == :declared_in_current_defined_in_parent
627
+ # The autoload constant has been removed
622
628
self . autoload? ( :DeclaredInCurrentDefinedInParent ) . should == nil
623
629
const_defined? ( :DeclaredInCurrentDefinedInParent ) . should == false
630
+ self . should_not have_constant ( :DeclaredInCurrentDefinedInParent )
624
631
-> { const_get ( :DeclaredInCurrentDefinedInParent ) } . should raise_error ( NameError )
625
632
end
626
633
@@ -630,7 +637,7 @@ class LexicalScope
630
637
end
631
638
632
639
ruby_version_is "" ..."3.1" do
633
- it "and fails when finding the undefined autoload constant in the current scope when declared in current and defined in parent" do
640
+ it "fails when finding the undefined autoload constant in the current scope when declared in current and defined in parent" do
634
641
@remove << :DeclaredInCurrentDefinedInParent
635
642
module ModuleSpecs ::Autoload
636
643
ScratchPad . record -> {
0 commit comments