Permalink
Browse files

Improve path searching during auto activation. Fixes #227

  • Loading branch information...
1 parent cf9872b commit abfb4b08de11a6d61fa317c2c18da22ea274d612 @evanphx evanphx committed Oct 7, 2012
Showing with 31 additions and 1 deletion.
  1. +1 −1 lib/rubygems.rb
  2. +10 −0 lib/rubygems/specification.rb
  3. +20 −0 test/rubygems/test_gem_specification.rb
View
@@ -153,7 +153,7 @@ def self.try_activate path
# TODO: use find_all and bork if ambiguous
- spec = Gem::Specification.find_by_path path
+ spec = Gem::Specification.find_inactive_by_path path
return false unless spec
begin
@@ -797,6 +797,16 @@ def self.find_by_path path
end
##
+ # Return the best specification that contains the file matching +path+
+ # amongst the specs that are not activated.
+
+ def self.find_inactive_by_path path
+ self.find { |spec|
+ spec.contains_requirable_file? path unless spec.activated?
+ }
+ end
+
+ ##
# Return currently unresolved specs that contain the file matching +path+.
def self.find_in_unresolved path
@@ -1841,6 +1841,26 @@ def test_find_by_name
end
end
+ def test_find_by_path
+ a = new_spec "foo", "1", nil, "lib/foo.rb"
+
+ install_specs a
+
+ assert_equal a, Gem::Specification.find_by_path('foo')
+ a.activate
+ assert_equal a, Gem::Specification.find_by_path('foo')
+ end
+
+ def test_find_inactive_by_path
+ a = new_spec "foo", "1", nil, "lib/foo.rb"
+
+ install_specs a
+
+ assert_equal a, Gem::Specification.find_inactive_by_path('foo')
+ a.activate
+ assert_equal nil, Gem::Specification.find_inactive_by_path('foo')
+ end
+
def util_setup_deps
@gem = quick_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []

0 comments on commit abfb4b0

Please sign in to comment.