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 foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
23 File.open foo_path, 'w' do |io|
24 io.puts 'I changed it!'
27 @cmd.options[:args] = %w[a]
33 assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
35 out = @ui.output.split "\n"
37 assert_equal "Restoring gem(s) to pristine condition...", out.shift
38 assert_equal "Restored #{a.full_name}", out.shift
39 assert out.empty?, out.inspect
43 a = quick_gem 'a' do |s| s.executables = %w[foo] end
44 FileUtils.mkdir_p File.join(@tempdir, 'bin')
45 File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
46 fp.puts "#!/usr/bin/ruby"
51 gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
55 @cmd.handle_options %w[--all]
61 assert File.exist?(gem_bin)
63 out = @ui.output.split "\n"
65 assert_equal "Restoring gem(s) to pristine condition...", out.shift
66 assert_equal "Restored #{a.full_name}", out.shift
67 assert out.empty?, out.inspect
70 def test_execute_missing_cache_gem
71 a = quick_gem 'a' do |s| s.executables = %w[foo] end
72 FileUtils.mkdir_p File.join(@tempdir, 'bin')
73 File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
74 fp.puts "#!/usr/bin/ruby"
79 FileUtils.rm File.join(@gemhome, 'cache', "#{a.full_name}.gem")
81 @cmd.options[:args] = %w[a]
87 out = @ui.output.split "\n"
89 assert_equal "Restoring gem\(s\) to pristine condition...", out.shift
90 assert out.empty?, out.inspect
92 assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n",
96 def test_execute_no_gem
97 @cmd.options[:args] = %w[]
99 e = assert_raise Gem::CommandLineError do
105 assert_match %r|specify a gem name|, e.message