Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ #require now checks unresolved dependencies first

  • Loading branch information...
commit b06875ed602abf08e9ee444ebd2140284c4c6fbe 1 parent 06bcc8d
@zenspider zenspider authored
View
17 lib/rubygems/custom_require.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

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 Owner

I don't see how:

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

Sounds like you have a broken environment.

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 Owner

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

@zenspider Owner

ruby -Ilib -S rake

will work for now.

@zenspider Owner

Fixed. Thanks for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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)
View
6 lib/rubygems/gem_path_searcher.rb
@@ -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
12 test/rubygems/test_gem.rb
@@ -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'
@miaout17

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

I don't see how:

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

Sounds like you have a broken environment.

@miaout17

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

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

@zenspider

ruby -Ilib -S rake

will work for now.

@zenspider

Fixed. Thanks for pointing this out.

Please sign in to comment.
Something went wrong with that request. Please try again.