Skip to content

Commit

Permalink
loaded_from should change depending on if it's a default gem
Browse files Browse the repository at this point in the history
we should set loaded_from do the default_spec_file if we're installing a
default gem.
  • Loading branch information
tenderlove committed Apr 15, 2015
1 parent 023fb58 commit c058d92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/rubygems/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,29 @@ def self.at path, options = {}
new package, options
end

class FakePackage < Struct.new :spec
def extract_files destination_dir, pattern = '*'
FileUtils.mkdir_p destination_dir

spec.files.each do |file|
file = File.join destination_dir, file
next if File.exist? file
FileUtils.mkdir_p File.dirname(file)
File.open file, 'w' do |fp| fp.puts "# #{file}" end
end
end

def copy_to path
end
end

##
# Construct an installer object for an ephemeral gem (one where we don't
# actually have a .gem file, just a spec)

def self.for_spec spec, options = {}
# FIXME: we should have a real Package class for this
new Struct.new(:spec).new(spec), options
new FakePackage.new(spec), options
end

##
Expand Down Expand Up @@ -257,12 +273,12 @@ def install

FileUtils.mkdir_p gem_dir

spec.loaded_from = spec_file

if @options[:install_as_default]
spec.loaded_from = default_spec_file
extract_bin
write_default_spec
else
spec.loaded_from = spec_file
extract_files

build_extensions
Expand Down
7 changes: 7 additions & 0 deletions test/rubygems/test_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,13 @@ def test_dir
assert_match %r!/gemhome/gems/a-2$!, @installer.dir
end

def test_default_gem_loaded_from
spec = util_spec 'a'
installer = Gem::Installer.for_spec spec, :install_as_default => true
installer.install
assert_predicate spec, :default_gem?
end

def test_default_gem
FileUtils.rm_f File.join(Gem.dir, 'specifications')

Expand Down

0 comments on commit c058d92

Please sign in to comment.