Skip to content

Commit

Permalink
+ #require now checks unresolved dependencies first
Browse files Browse the repository at this point in the history
  • Loading branch information
zenspider committed Feb 24, 2011
1 parent 06bcc8d commit b06875e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
17 changes: 15 additions & 2 deletions lib/rubygems/custom_require.rb
Expand Up @@ -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

This comment has been minimized.

Copy link
@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)

This comment has been minimized.

Copy link
@zenspider

zenspider Feb 25, 2011

Author Contributor

I don't see how:

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

Sounds like you have a broken environment.

This comment has been minimized.

Copy link
@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 :)

This comment has been minimized.

Copy link
@zenspider

zenspider Feb 25, 2011

Author Contributor

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

This comment has been minimized.

Copy link
@zenspider

zenspider Feb 25, 2011

Author Contributor

ruby -Ilib -S rake

will work for now.

This comment has been minimized.

Copy link
@zenspider

zenspider Feb 25, 2011

Author 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)
Expand Down
6 changes: 4 additions & 2 deletions lib/rubygems/gem_path_searcher.rb
Expand Up @@ -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
Expand All @@ -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 || []
Expand Down
12 changes: 12 additions & 0 deletions test/rubygems/test_gem.rb
Expand Up @@ -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'
Expand Down

0 comments on commit b06875e

Please sign in to comment.