aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/module/autoload_spec.rb50
-rw-r--r--spec/ruby/core/module/fixtures/autoload_never_set.rb0
2 files changed, 50 insertions, 0 deletions
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb
index d7b212183b..a72ae7735b 100644
--- a/spec/ruby/core/module/autoload_spec.rb
+++ b/spec/ruby/core/module/autoload_spec.rb
@@ -448,6 +448,56 @@ describe "Module#autoload" do
end
end
end
+
+ it "raises a NameError in each thread if the constant is not set" do
+ file = fixture(__FILE__, "autoload_never_set.rb")
+ start = false
+
+ threads = Array.new(10) do
+ Thread.new do
+ Thread.pass until start
+ begin
+ ModuleSpecs::Autoload.autoload :NeverSetConstant, file
+ Thread.pass
+ ModuleSpecs::Autoload::NeverSetConstant
+ rescue NameError => e
+ e
+ ensure
+ Thread.pass
+ end
+ end
+ end
+
+ start = true
+ threads.each { |t|
+ t.value.should be_an_instance_of(NameError)
+ }
+ end
+
+ it "raises a LoadError in each thread if the file does not exist" do
+ file = fixture(__FILE__, "autoload_does_not_exist.rb")
+ start = false
+
+ threads = Array.new(10) do
+ Thread.new do
+ Thread.pass until start
+ begin
+ ModuleSpecs::Autoload.autoload :FileDoesNotExist, file
+ Thread.pass
+ ModuleSpecs::Autoload::FileDoesNotExist
+ rescue LoadError => e
+ e
+ ensure
+ Thread.pass
+ end
+ end
+ end
+
+ start = true
+ threads.each { |t|
+ t.value.should be_an_instance_of(LoadError)
+ }
+ end
end
it "loads the registered constant even if the constant was already loaded by another thread" do
diff --git a/spec/ruby/core/module/fixtures/autoload_never_set.rb b/spec/ruby/core/module/fixtures/autoload_never_set.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_never_set.rb