Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 2 commits into from

3 participants

Clayton Wheeler Yorick Peterse Dirkjan Bussink
Clayton Wheeler

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 ..."

alindeman 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
end
end
+ it "entries should NOT raise a NameError when calling #autoload, requiring the module directly, and calling #autoload again" do
+ fx_p = fixture(__FILE__, "autoload_p.rb")
+ ModuleSpecs.autoload(:P, fx_p)
+ require fx_p
+ ModuleSpecs.autoload(:P, fx_p)
+ lambda { ModuleSpecs::P::P1 }.should_not raise_error(NameError)

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
alindeman alindeman 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
alindeman alindeman 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
Yorick Peterse

Closing this one due to:

  1. Being quite old and not merge-able without manual work
  2. The specs being sub-par (see @dbussink's comment)
  3. The spec description being fuzzy
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
View
@@ -290,6 +290,14 @@ class Y2
end
end
+ it "entries should NOT raise a NameError when calling #autoload, requiring the module directly, and calling #autoload again" do
+ fx_p = fixture(__FILE__, "autoload_p.rb")
+ ModuleSpecs.autoload(:P, fx_p)
+ require fx_p
+ ModuleSpecs.autoload(:P, fx_p)
+ lambda { ModuleSpecs::P::P1 }.should_not raise_error(NameError)

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
+ end
+
ruby_version_is "1.9" do
it "calls #to_path on non-string filenames" do
p = mock('path')
5 core/module/fixtures/autoload_p.rb
View
@@ -0,0 +1,5 @@
+module ModuleSpecs
+ class P
+ P1 = :p1
+ end
+end
Something went wrong with that request. Please try again.