Skip to content

Commit f94c490

Browse files
committed
Improve autoload specs
1 parent 6ee8d87 commit f94c490

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

spec/ruby/core/module/autoload_spec.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,17 @@ class LexicalScope
568568
LexicalScope::DeclaredInParentDefinedInCurrent.should == :declared_in_parent_defined_in_current
569569
end
570570

571-
# Basically, the parent autoload constant remains in a "undefined" state
572571
self.autoload?(:DeclaredInParentDefinedInCurrent).should == nil
573572
const_defined?(:DeclaredInParentDefinedInCurrent).should == false
574573
-> { 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
575582

576583
ModuleSpecs::Autoload::LexicalScope.send(:remove_const, :DeclaredInParentDefinedInCurrent)
577584
end
@@ -592,13 +599,11 @@ module Autoload
592599
-> {
593600
DeclaredInCurrentDefinedInParent
594601
}.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)
598603

599604
-> {
600605
DeclaredInCurrentDefinedInParent
601-
}.should_not complain(/.*/, verbose: true)
606+
}.should_not complain(verbose: true)
602607
self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
603608
const_defined?(:DeclaredInCurrentDefinedInParent).should == false
604609
ModuleSpecs.const_defined?(:DeclaredInCurrentDefinedInParent).should == true
@@ -607,8 +612,9 @@ module Autoload
607612
end
608613
end
609614

615+
# like net/https used to do `module Net; autoload :OpenSSL, 'openssl'; end` before https://github.com/ruby/net-http/commit/369c3fd708
610616
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
612618
@remove << :DeclaredInCurrentDefinedInParent
613619
module ModuleSpecs::Autoload
614620
ScratchPad.record -> {
@@ -617,10 +623,11 @@ module ModuleSpecs::Autoload
617623

618624
class LexicalScope
619625
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
622628
self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
623629
const_defined?(:DeclaredInCurrentDefinedInParent).should == false
630+
self.should_not have_constant(:DeclaredInCurrentDefinedInParent)
624631
-> { const_get(:DeclaredInCurrentDefinedInParent) }.should raise_error(NameError)
625632
end
626633

@@ -630,7 +637,7 @@ class LexicalScope
630637
end
631638

632639
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
634641
@remove << :DeclaredInCurrentDefinedInParent
635642
module ModuleSpecs::Autoload
636643
ScratchPad.record -> {

0 commit comments

Comments
 (0)