From fb85a428605265a8fd449b0702a4dd88cb6f3b20 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 7 May 2019 12:52:24 +0200 Subject: Add an optional `inherit` argument to Module#autoload? [Feature #15777] Closes: https://github.com/ruby/ruby/pull/2173 --- spec/ruby/core/module/autoload_spec.rb | 12 ++++++++++++ spec/ruby/core/module/fixtures/classes.rb | 6 ++++++ 2 files changed, 18 insertions(+) (limited to 'spec/ruby') diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index eaad4b8df6..09fbafd51c 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -11,6 +11,18 @@ describe "Module#autoload?" do it "returns nil if no file has been registered for a constant" do ModuleSpecs::Autoload.autoload?(:Manualload).should be_nil end + + it "returns the name of the file that will be autoloaded if an ancestor defined that autoload" do + ModuleSpecs::Autoload::Parent.autoload :AnotherAutoload, "another_autoload.rb" + ModuleSpecs::Autoload::Child.autoload?(:AnotherAutoload).should == "another_autoload.rb" + end + + ruby_version_is "2.7" do + it "returns nil if an ancestor defined that autoload but recursion is disabled" do + ModuleSpecs::Autoload::Parent.autoload :AnotherAutoload, "another_autoload.rb" + ModuleSpecs::Autoload::Child.autoload?(:AnotherAutoload, false).should be_nil + end + end end describe "Module#autoload" do diff --git a/spec/ruby/core/module/fixtures/classes.rb b/spec/ruby/core/module/fixtures/classes.rb index f93c39683e..ef70eaf9cf 100644 --- a/spec/ruby/core/module/fixtures/classes.rb +++ b/spec/ruby/core/module/fixtures/classes.rb @@ -386,6 +386,12 @@ module ModuleSpecs end end + class Parent + end + + class Child < Parent + end + module FromThread module A autoload :B, fixture(__FILE__, "autoload_empty.rb") -- cgit v1.2.3