2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/indexer'
4 require 'rubygems/commands/mirror_command'
6 class TestGemCommandsMirrorCommand < RubyGemTestCase
11 @cmd = Gem::Commands::MirrorCommand.new
17 gems_dir = File.join @tempdir, 'gems'
18 mirror = File.join @tempdir, 'mirror'
20 FileUtils.mkdir_p gems_dir
21 FileUtils.mkdir_p mirror
23 Dir[File.join(@gemhome, 'cache', '*.gem')].each do |gem|
24 FileUtils.mv gem, gems_dir
28 Gem::Indexer.new(@tempdir).generate_index
31 orig_HOME = ENV['HOME']
32 ENV['HOME'] = @tempdir
33 Gem.instance_variable_set :@user_home, nil
35 File.open File.join(Gem.user_home, '.gemmirrorrc'), 'w' do |fp|
37 # tempdir could be a drive+path (under windows)
38 if @tempdir.match(/[a-z]:/i)
39 fp.puts "- from: file:///#{@tempdir}"
41 fp.puts "- from: file://#{@tempdir}"
43 fp.puts " to: #{mirror}"
50 assert File.exist?(File.join(mirror, 'gems', "#{@a1.full_name}.gem"))
51 assert File.exist?(File.join(mirror, 'gems', "#{@a2.full_name}.gem"))
52 assert File.exist?(File.join(mirror, 'gems', "#{@b2.full_name}.gem"))
53 assert File.exist?(File.join(mirror, 'gems', "#{@c1_2.full_name}.gem"))
54 assert File.exist?(File.join(mirror, "Marshal.#{@marshal_version}"))
56 orig_HOME.nil? ? ENV.delete('HOME') : ENV['HOME'] = orig_HOME
57 Gem.instance_variable_set :@user_home, nil
60 end if ''.respond_to? :to_xs