2011-01-18 19:08:49 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/pristine_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsPristineCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@cmd = Gem::Commands::PristineCommand.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
2011-03-07 03:44:45 -05:00
|
|
|
a = quick_spec 'a' do |s| s.executables = %w[foo] end
|
2007-11-10 02:48:56 -05:00
|
|
|
FileUtils.mkdir_p File.join(@tempdir, 'bin')
|
|
|
|
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
|
|
|
|
|
|
|
|
File.open foo_path, 'w' do |io|
|
|
|
|
io.puts 'I changed it!'
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal "Restoring gem(s) to pristine condition...", out.shift
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_empty out, out.inspect
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_all
|
2011-03-07 03:44:45 -05:00
|
|
|
a = quick_spec 'a' do |s| s.executables = %w[foo] end
|
2007-11-10 02:48:56 -05:00
|
|
|
FileUtils.mkdir_p File.join(@tempdir, 'bin')
|
|
|
|
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
FileUtils.rm gem_bin
|
|
|
|
|
|
|
|
@cmd.handle_options %w[--all]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert File.exist?(gem_bin)
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal "Restoring gem(s) to pristine condition...", out.shift
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_empty out, out.inspect
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_missing_cache_gem
|
2011-03-07 03:44:45 -05:00
|
|
|
a = quick_spec 'a' do |s|
|
|
|
|
s.executables = %w[foo]
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
FileUtils.mkdir_p File.join(@tempdir, 'bin')
|
2011-03-07 03:44:45 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
a_data = nil
|
|
|
|
open File.join(@gemhome, 'cache', a.file_name), 'rb' do |fp|
|
|
|
|
a_data = fp.read
|
|
|
|
end
|
|
|
|
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
util_setup_spec_fetcher a
|
|
|
|
|
|
|
|
Gem::RemoteFetcher.fetcher.data["http://gems.example.com/gems/#{a.file_name}"] = a_data
|
|
|
|
|
|
|
|
FileUtils.rm Gem.cache_gem(a.file_name, @gemhome)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
[
|
|
|
|
"Restoring gem\(s\) to pristine condition...",
|
|
|
|
"Restored a-1",
|
|
|
|
"Cached gem for a-2 not found, attempting to fetch...",
|
|
|
|
"Restored a-2",
|
|
|
|
"Restored a-3.a"
|
|
|
|
].each do |line|
|
|
|
|
assert_equal line, out.shift
|
|
|
|
end
|
2011-03-07 03:39:39 -05:00
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
assert_empty out, out.inspect
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_no_gem
|
|
|
|
@cmd.options[:args] = %w[]
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::CommandLineError do
|
2007-11-10 02:48:56 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r|specify a gem name|, e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|