Skip to content

Commit acdecc0

Browse files
committed
Add spec for autoloading with require twice from the same file
1 parent ca2593a commit acdecc0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

spec/ruby/core/module/autoload_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,29 @@ module ModuleSpecs::Autoload
274274
end
275275
end
276276

277+
describe "after the autoload is triggered by require" do
278+
before :each do
279+
@path = tmp("autoload.rb")
280+
end
281+
282+
after :each do
283+
rm_r @path
284+
end
285+
286+
it "the mapping feature to autoload is removed, and a new autoload with the same path is considered" do
287+
ModuleSpecs::Autoload.autoload :RequireMapping1, @path
288+
touch(@path) { |f| f.puts "ModuleSpecs::Autoload::RequireMapping1 = 1" }
289+
ModuleSpecs::Autoload::RequireMapping1.should == 1
290+
291+
$LOADED_FEATURES.delete(@path)
292+
ModuleSpecs::Autoload.autoload :RequireMapping2, @path[0...-3]
293+
touch(@path) { |f| f.puts "ModuleSpecs::Autoload::RequireMapping2 = 2" }
294+
ModuleSpecs::Autoload::RequireMapping2.should == 2
295+
296+
ModuleSpecs::Autoload.send :remove_const, :RequireMapping2
297+
end
298+
end
299+
277300
describe "during the autoload before the constant is assigned" do
278301
before :each do
279302
@path = fixture(__FILE__, "autoload_during_autoload.rb")

0 commit comments

Comments
 (0)