Permalink
Browse files

+ #require now checks unresolved dependencies first

  • Loading branch information...
1 parent 06bcc8d commit b06875ed602abf08e9ee444ebd2140284c4c6fbe @zenspider zenspider committed Feb 24, 2011
Showing with 31 additions and 4 deletions.
  1. +15 −2 lib/rubygems/custom_require.rb
  2. +4 −2 lib/rubygems/gem_path_searcher.rb
  3. +12 −0 test/rubygems/test_gem.rb
@@ -25,8 +25,21 @@ module Kernel
# The normal <tt>require</tt> functionality of returning false if
# that file has already been loaded is preserved.
- def require(path) # :doc:
- gem_original_require path
+ def require path
+ if Gem._unresolved.specs.empty? then
miaout17
miaout17 Feb 25, 2011 Contributor

This breaks tests in current master branch. The error message is:

rake aborted!
undefined method `_unresolved' for Gem:Module
/home/miaout17/work/rubygems/Rakefile:12:in `<top (required)>'
(See full trace by running task with --trace)
zenspider
zenspider Feb 25, 2011 Contributor

I don't see how:

https://github.com/rubygems/rubygems/blob/master/lib/rubygems.rb#L322

Sounds like you have a broken environment.

miaout17
miaout17 Feb 25, 2011 Contributor

Oh....I think the thing I missed is I must run ruby setup.rb to install the gem into system, then when I run rake and the test passed.

Is there any way to run unit test without affecting system rubygems?

BTW, does rubygems have "how to contribute and test guideline" document?

Thanks for your replying :)

zenspider
zenspider Feb 25, 2011 Contributor

OK. I have a repro. I'll work on a fix after my workout.

zenspider
zenspider Feb 25, 2011 Contributor

ruby -Ilib -S rake

will work for now.

zenspider
zenspider Feb 25, 2011 Contributor

Fixed. Thanks for pointing this out.

+ gem_original_require path
+ else
+ specs = Gem.searcher.find_all path
+
+ if specs.empty? then
+ gem_original_require path
+ else
+ # TODO: actually check the unresolves specs only
+ spec = specs.first
+ Gem.activate spec.name, spec.version # FIX: holy shit this is dumb
+ return gem_original_require(path)
+ end
+ end
rescue LoadError => load_error
if load_error.message.end_with?(path) and Gem.try_activate(path) then
return gem_original_require(path)
@@ -43,7 +43,8 @@ def initialize
# only that there is a match.
def find(glob)
- @gemspecs.find do |spec|
+ # HACK violation
+ (Gem._unresolved.specs + @gemspecs).find do |spec|
# TODO: inverted responsibility
matching_file? spec, glob
end
@@ -53,7 +54,8 @@ def find(glob)
# Works like #find, but finds all gemspecs matching +glob+.
def find_all(glob)
- @gemspecs.select do |spec|
+ # HACK violation
+ (Gem._unresolved.specs + @gemspecs).select do |spec|
# TODO: inverted responsibility
matching_file? spec, glob
end || []
View
@@ -43,6 +43,18 @@ def test_self_activate
assert_activate %w[foo-1], foo
end
+ def test_self_activate_via_require
+ a1 = new_spec "a", "1", "b" => "= 1"
+ b1 = new_spec "b", "1", nil, "lib/b/c.rb"
+ b2 = new_spec "b", "2", nil, "lib/b/c.rb"
+
+ install_specs a1, b1
+
+ Gem.activate "a", "= 1"
+ require "b/c"
+ assert_equal %w(a-1 b-1), Gem.loaded_specs.values.map(&:full_name).sort
+ end
+
def test_self_activate_loaded
util_spec 'foo', '1'
assert Gem.activate 'foo'

0 comments on commit b06875e

Please sign in to comment.