diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-05-31 18:22:49 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-05-31 18:22:49 +0200 |
commit | 34776105c8a6739ca3aad1de4a2c942f4a8f2f29 (patch) | |
tree | 0103cf2cc89c1322d8c3e88fff0a80b54db8320b /spec/ruby/core/module | |
parent | f4502b001a665109bf776f9037ecbc52cb5f2d88 (diff) |
Update to ruby/spec@4e486fa
Diffstat (limited to 'spec/ruby/core/module')
-rw-r--r-- | spec/ruby/core/module/autoload_spec.rb | 26 | ||||
-rw-r--r-- | spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index 6f0ca49dcf..85a0d067d1 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -294,6 +294,32 @@ describe "Module#autoload" do ScratchPad.recorded.should == [nil, nil] @check.call.should == ["constant", nil] end + + it "does not raise an error if the autoload constant was not defined" do + module ModuleSpecs::Autoload + autoload :RequiredDirectlyNoConstant, fixture(__FILE__, "autoload_required_directly_no_constant.rb") + end + @path = fixture(__FILE__, "autoload_required_directly_no_constant.rb") + @remove << :RequiredDirectlyNoConstant + @check = -> { + [ + defined?(ModuleSpecs::Autoload::RequiredDirectlyNoConstant), + ModuleSpecs::Autoload.constants(false).include?(:RequiredDirectlyNoConstant), + ModuleSpecs::Autoload.const_defined?(:RequiredDirectlyNoConstant), + ModuleSpecs::Autoload.autoload?(:RequiredDirectlyNoConstant) + ] + } + ScratchPad.record @check + @check.call.should == ["constant", true, true, @path] + $:.push File.dirname(@path) + begin + require "autoload_required_directly_no_constant.rb" + ensure + $:.pop + end + ScratchPad.recorded.should == [nil, true, false, nil] + @check.call.should == [nil, true, false, nil] + end end describe "after the autoload is triggered by require" do diff --git a/spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb b/spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb new file mode 100644 index 0000000000..25e08c1129 --- /dev/null +++ b/spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb @@ -0,0 +1,2 @@ +block = ScratchPad.recorded +ScratchPad.record(block.call) |