Skip to content
This repository

Added test for autoload issue observed with BioRuby tests on JRuby. #136

Open
wants to merge 2 commits into from

2 participants

Clayton Wheeler Dirkjan Bussink
Clayton Wheeler
csw commented

Many BioRuby unit tests fail on JRuby when run as a suite; this adds a minimal test case for the root cause of that problem.

Specifically, on JRuby but not MRI, when:

  • a module creates an autoload entry
  • a file which would be loaded by that entry is instead loaded by directly invoking require
  • the autoload entry is set up again with another call to the parent module's #autoload method

Then subsequent access to the child module fails with "NameError: uninitialized constant ..."

Andy Lindeman alindeman referenced this pull request in jruby/jruby
Closed

Fixes JRUBY-6658 #176

Dirkjan Bussink dbussink commented on the diff
core/module/autoload_spec.rb
@@ -290,6 +290,14 @@ class Y2
290 290
     end
291 291
   end
292 292
 
  293
+  it "entries should NOT raise a NameError when calling #autoload, requiring the module directly, and calling #autoload again" do
  294
+    fx_p = fixture(__FILE__, "autoload_p.rb")
  295
+    ModuleSpecs.autoload(:P, fx_p)
  296
+    require fx_p
  297
+    ModuleSpecs.autoload(:P, fx_p)
  298
+    lambda { ModuleSpecs::P::P1 }.should_not raise_error(NameError)
1
Dirkjan Bussink Collaborator

Please don't assert that it should not throw exceptions. This spec would pass if for example it throws a different type of exception. Try to find something that actually asserts how it behaves. In this case probably something like:

ModuleSpecs::P::P1.should == :p1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
xb xb referenced this pull request from a commit in xb/jruby
Andy Lindeman Fixes JRUBY-6658
* If an autoload is defined, yet the constant is defined by other means,
  another autoload for the same constant does not reset the process.
* Fixes rubyspec/rubyspec#136 under JRuby
db3fd5e
Douglas Campos qmx referenced this pull request from a commit in qmx/jruby
Andy Lindeman Fixes JRUBY-6658
* If an autoload is defined, yet the constant is defined by other means,
  another autoload for the same constant does not reset the process.
* Fixes rubyspec/rubyspec#136 under JRuby
22cd6f9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
8  core/module/autoload_spec.rb
@@ -290,6 +290,14 @@ class Y2
290 290
     end
291 291
   end
292 292
 
  293
+  it "entries should NOT raise a NameError when calling #autoload, requiring the module directly, and calling #autoload again" do
  294
+    fx_p = fixture(__FILE__, "autoload_p.rb")
  295
+    ModuleSpecs.autoload(:P, fx_p)
  296
+    require fx_p
  297
+    ModuleSpecs.autoload(:P, fx_p)
  298
+    lambda { ModuleSpecs::P::P1 }.should_not raise_error(NameError)
  299
+  end
  300
+
293 301
   ruby_version_is "1.9" do
294 302
     it "calls #to_path on non-string filenames" do
295 303
       p = mock('path')
5  core/module/fixtures/autoload_p.rb
... ...
@@ -0,0 +1,5 @@
  1
+module ModuleSpecs
  2
+  class P
  3
+    P1 = :p1
  4
+  end
  5
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.