2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/pristine_command'
5 class TestGemCommandsPristineCommand < RubyGemTestCase
9 @cmd = Gem::Commands::PristineCommand.new
13 a = quick_gem 'a' do |s| s.executables = %w[foo] end
14 FileUtils.mkdir_p File.join(@tempdir, 'bin')
15 File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
16 fp.puts "#!/usr/bin/ruby"
21 @cmd.options[:args] = %w[a]
27 out = @ui.output.split "\n"
29 assert_equal "Restoring gem(s) to pristine condition...", out.shift
30 assert_equal "#{a.full_name} is in pristine condition", out.shift
31 assert out.empty?, out.inspect
35 a = quick_gem 'a' do |s| s.executables = %w[foo] end
36 FileUtils.mkdir_p File.join(@tempdir, 'bin')
37 File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
38 fp.puts "#!/usr/bin/ruby"
43 gem_bin = File.join @gemhome, 'gems', "#{a.full_name}", 'bin', 'foo'
47 @cmd.handle_options %w[--all]
53 out = @ui.output.split "\n"
55 assert_equal "Restoring gem(s) to pristine condition...", out.shift
56 assert_equal "Restoring 1 file to #{a.full_name}...", out.shift
57 assert_equal " #{gem_bin}", out.shift
58 assert out.empty?, out.inspect
61 def test_execute_missing_cache_gem
62 a = quick_gem 'a' do |s| s.executables = %w[foo] end
63 FileUtils.mkdir_p File.join(@tempdir, 'bin')
64 File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
65 fp.puts "#!/usr/bin/ruby"
70 FileUtils.rm File.join(@gemhome, 'cache', "#{a.full_name}.gem")
72 @cmd.options[:args] = %w[a]
78 out = @ui.output.split "\n"
80 assert_equal "Restoring gem\(s\) to pristine condition...", out.shift
81 assert out.empty?, out.inspect
83 assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n",
87 def test_execute_no_gem
88 @cmd.options[:args] = %w[]
90 e = assert_raise Gem::CommandLineError do
96 assert_match %r|specify a gem name|, e.message