2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rubygems/user_interaction"
|
2019-04-14 02:01:35 -04:00
|
|
|
require "support/path"
|
|
|
|
require "fileutils"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
module Spec
|
|
|
|
module Rubygems
|
|
|
|
DEPS = begin
|
2019-04-14 02:01:35 -04:00
|
|
|
{
|
2018-11-02 19:07:56 -04:00
|
|
|
# artifice doesn't support rack 2.x now.
|
2019-04-14 02:01:35 -04:00
|
|
|
"rack" => "< 2.0",
|
|
|
|
"rack-test" => "~> 1.1",
|
2018-11-02 19:07:56 -04:00
|
|
|
"artifice" => "~> 0.6.0",
|
|
|
|
"compact_index" => "~> 0.11.0",
|
|
|
|
"sinatra" => "~> 1.4.7",
|
|
|
|
# Rake version has to be consistent for tests to pass
|
2019-04-14 02:01:35 -04:00
|
|
|
"rake" => "12.3.2",
|
|
|
|
"builder" => "~> 3.2",
|
|
|
|
# ruby-graphviz is used by the viz tests
|
|
|
|
"ruby-graphviz" => nil,
|
2018-11-02 19:07:56 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.setup
|
|
|
|
Gem.clear_paths
|
|
|
|
|
|
|
|
ENV["BUNDLE_PATH"] = nil
|
|
|
|
ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s
|
2019-04-14 02:01:35 -04:00
|
|
|
ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
manifest = DEPS.to_a.sort_by(&:first).map {|k, v| "#{k} => #{v}\n" }
|
2019-04-14 02:01:35 -04:00
|
|
|
manifest_path = Path.base_system_gems.join("manifest.txt")
|
2018-11-02 19:07:56 -04:00
|
|
|
# it's OK if there are extra gems
|
2019-04-14 02:01:35 -04:00
|
|
|
if !manifest_path.file? || !(manifest - manifest_path.readlines).empty?
|
2018-11-02 19:07:56 -04:00
|
|
|
FileUtils.rm_rf(Path.base_system_gems)
|
|
|
|
FileUtils.mkdir_p(Path.base_system_gems)
|
|
|
|
puts "installing gems for the tests to use..."
|
|
|
|
install_gems(DEPS)
|
2019-04-14 02:01:35 -04:00
|
|
|
manifest_path.open("w") {|f| f << manifest.join }
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
ENV["HOME"] = Path.home.to_s
|
|
|
|
ENV["TMPDIR"] = Path.tmpdir.to_s
|
|
|
|
|
|
|
|
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.install_gems(gems)
|
|
|
|
reqs, no_reqs = gems.partition {|_, req| !req.nil? && !req.split(" ").empty? }
|
|
|
|
no_reqs.map!(&:first)
|
|
|
|
reqs.map! {|name, req| "'#{name}:#{req}'" }
|
|
|
|
deps = reqs.concat(no_reqs).join(" ")
|
2019-04-14 02:01:35 -04:00
|
|
|
gem = Spec::Path.ruby_core? ? ENV["BUNDLE_GEM"] : "#{Gem.ruby} -S gem"
|
|
|
|
cmd = "#{gem} install #{deps} --no-document --conservative"
|
2018-11-02 19:07:56 -04:00
|
|
|
puts cmd
|
|
|
|
system(cmd) || raise("Installing gems #{deps} for the tests to use failed!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|