Skip to content
Permalink
Browse files

Get the test passing

  • Loading branch information...
matthewd committed May 5, 2019
1 parent 4da5a30 commit 6872dac3344027997d5788b61c5d3780c672fa21
Showing with 51 additions and 23 deletions.
  1. +1 −0 Rakefile
  2. +11 −3 lib/gel/environment.rb
  3. +3 −3 lib/gel/lock_loader.rb
  4. +5 −2 lib/gel/resolved_gem_set.rb
  5. +18 −15 test/command/install_gem_test.rb
  6. +13 −0 test/test_helper.rb
@@ -15,6 +15,7 @@ Rake::TestTask.new(:test) do |t|
end

FIXTURE_GEMS = [
["rack", "2.0.6"],
["rack", "2.0.3"],
["rack", "0.1.0"],
["hoe", "3.0.0"],
@@ -206,8 +206,8 @@ def self.solve_for_gemfile(store: store(), output: nil, gemfile: Gel::Environmen
auto_install_pub_grub!
with_root_store do
gem "pub_grub"
require_relative "pub_grub/solver"
end
require_relative "pub_grub/solver"

strategy = gem_set && preference_strategy && preference_strategy.call(gem_set)
solver = Gel::PubGrub::Solver.new(gemfile: gemfile, catalog_set: catalog_set, platforms: ["ruby"], strategy: strategy)
@@ -228,7 +228,10 @@ def self.solve_for_gemfile(store: store(), output: nil, gemfile: Gel::Environmen
end
output.puts
else
PubGrub.logger.info "Resolving dependencies..."
if solver.respond_to?(:logger)
solver.logger.info "Resolving dependencies..."
end

solver.work until solver.solved?
end

@@ -459,8 +462,13 @@ def self.gems_from_lock(name_version_pairs)
end

def self.activate_gem(gem, why: nil)
raise gem.version.class.name unless gem.version.class == String
if activated_gems[gem.name]
raise activated_gems[gem.name].version.class.name unless activated_gems[gem.name].version.class == String
end

return if activated_gems[gem.name] && activated_gems[gem.name].version == gem.version
raise LoadError, "already activated #{gem.name} #{activated_gems[gem.name].version}" if activated_gems[gem.name]
raise LoadError, "already activated #{gem.name} #{activated_gems[gem.name].version} (can't activate #{gem.version})" if activated_gems[gem.name]

gem.dependencies.each do |dep, reqs|
self.gem(dep, *reqs.map { |(qual, ver)| "#{qual} #{ver}" }, why: ["required by #{gem.name} #{gem.version}", *why])
@@ -34,7 +34,7 @@ def activate(env, base_store, install: false, output: nil)
top_gems << name
filtered_gems[name] = true
end
elsif list = @gem_set.dependencies
elsif list = @gem_set.dependency_names
top_gems = list
top_gems.each do |name|
filtered_gems[name] = true
@@ -77,11 +77,11 @@ def activate(env, base_store, install: false, output: nil)
if resolved_gem.type == :gem
if installer && !base_store.gem?(name, resolved_gem.version, resolved_gem.platform)
require_relative "catalog"
catalogs = resolved_gem.body["remote"].map { |r| Gel::Catalog.new(r, work_pool: work_pool) }
catalogs = @gem_set.server_catalogs || resolved_gem.body["remote"].map { |r| Gel::Catalog.new(r, work_pool: work_pool) }
installer.install_gem(catalogs, name, resolved_gem.platform ? "#{resolved_gem.version}-#{resolved_gem.platform}" : resolved_gem.version)
end

locks[name] = resolved_gem.version
locks[name] = resolved_gem.version.to_s
else
if resolved_gem.type == :git
remote = resolved_gem.body["remote"].first
@@ -39,7 +39,6 @@ def initialize(filename = nil)
@filename = filename

@gems = {}
@catalogs = []
end

def catalog_for(resolved_gem)
@@ -85,7 +84,7 @@ def self.load(filename)
when "PLATFORMS"
result.platforms = body
when "DEPENDENCIES"
result.dependencies = body.map { |name| name.split(" ", 2)[0].chomp("!") }
result.dependencies = body.map { |name| name.chomp("!") }
when "RUBY VERSION"
result.ruby_version = body.first
when "BUNDLED WITH"
@@ -105,6 +104,10 @@ def gem_names
@gems.keys
end

def dependency_names
dependencies&.map { |dep| dep.split(" ").first }
end

def dump
lock_content = []

@@ -4,25 +4,28 @@

class InstallGemTest < Minitest::Test
def test_install_gem
stub_gem_mimer(source: "https://index.rubygems.org")
with_empty_store do |store|
with_empty_cache do
subprocess_output(<<-'END', store: store, lock_path: nil)
$stderr.reopen($stdout)
stub_request(:get, "https://rubygems.org/gems/rack-2.0.3.gem")
.to_return(body: File.open(fixture_file("rack-2.0.3.gem")))
stub_gem_mimer(source: "https://index.rubygems.org")
stub_request(:get, "https://rubygems.org/gems/rack-test-0.6.3.gem")
.to_return(body: File.open(fixture_file("rack-test-0.6.3.gem")))
stub_request(:get, "https://rubygems.org/gems/rack-2.0.6.gem")
.to_return(body: File.open(fixture_file("rack-2.0.6.gem")))
stub_request(:get, "https://rubygems.org/gems/pub_grub-0.5.0.gem")
.to_return(body: File.open(fixture_file("pub_grub-0.5.0.gem")))
stub_request(:get, "https://rubygems.org/gems/rack-test-0.6.3.gem")
.to_return(body: File.open(fixture_file("rack-test-0.6.3.gem")))
stub_request(:get, "https://rubygems.org/gems/pub_grub-0.5.0.gem")
.to_return(body: File.open(fixture_file("pub_grub-0.5.0.gem")))
with_empty_store do |store|
subprocess_output(<<-'END', store: store, lock_path: nil)
Gel::Environment.open(store)
require "gel/command"
require "gel/command/install_gem"
Gel::Command.run(["install-gem", "rack-test", "0.6.3"])
END
Gel::Environment.open(store)
require "gel/command"
require "gel/command/install_gem"
Gel::Command.run(["install-gem", "rack-test", "0.6.3"])
END
end

output = subprocess_output(<<-'END', store: store, lock_path: nil)
Gel::Environment.open(store)
@@ -35,7 +38,7 @@ def test_install_gem
END

# Both gems listed in the lockfile are activated
assert_equal "#{store.root}/gems/rack-2.0.3/lib", output.shift
assert_equal "#{store.root}/gems/rack-2.0.6/lib", output.shift
assert_equal "#{store.root}/gems/rack-test-0.6.3/lib", output.shift

# Other installed gems are not
@@ -36,6 +36,19 @@ def with_empty_store(multi: false, &block)
end
end

def with_empty_cache
previous = ENV["GEL_CACHE"]

begin
Dir.mktmpdir do |dir|
ENV["GEL_CACHE"] = dir
yield
end
ensure
ENV["GEL_CACHE"] = previous
end
end

def with_empty_multi_store
Dir.mktmpdir do |dir|
stores = {}

0 comments on commit 6872dac

Please sign in to comment.
You can’t perform that action at this time.