Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Gem activation now delays adding a gem to loaded_specs until after it…
… has been activated.

Gem.try_activate is now tested in the failing case
  • Loading branch information
drbrain committed May 4, 2011
1 parent a469423 commit 5936589
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/rubygems.rb
Expand Up @@ -208,8 +208,7 @@ def self.try_activate path
begin
spec.activate
rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
# TODO: actually test this
Gem::Specification.find(spec.name).activate
Gem::Specification.find_by_name(spec.name).activate
end

return true
Expand Down
3 changes: 2 additions & 1 deletion lib/rubygems/specification.rb
Expand Up @@ -706,11 +706,12 @@ def activate
return false if Gem.loaded_specs[self.name]

self.activated = true
Gem.loaded_specs[self.name] = self

activate_dependencies
add_self_to_load_path

Gem.loaded_specs[self.name] = self

return true
end

Expand Down
16 changes: 16 additions & 0 deletions test/rubygems/test_gem.rb
Expand Up @@ -932,6 +932,22 @@ def test_self_sources
assert_equal %w[http://gems.example.com/], Gem.sources
end

def test_self_try_activate_missing_dep
a = util_spec 'a', '1.0', 'b' => '>= 1.0'

a_file = File.join a.gem_dir, 'lib', 'a_file.rb'

write_file a_file do |io|
io.puts '# a_file.rb'
end

e = assert_raises Gem::LoadError do
Gem.try_activate 'a_file'
end

assert_match %r%Could not find b %, e.message
end

def test_ssl_available_eh
orig_Gem_ssl_available = Gem.ssl_available?

Expand Down

0 comments on commit 5936589

Please sign in to comment.