summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_commands_pristine_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_commands_pristine_command.rb')
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb115
1 files changed, 93 insertions, 22 deletions
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 4decdf8..aa1f3bf 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -16,8 +16,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase
def test_execute
a = quick_spec 'a' do |s| s.executables = %w[foo] end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
+
+ write_file File.join(@tempdir, 'bin', 'foo') do |fp|
fp.puts "#!/usr/bin/ruby"
end
@@ -25,7 +25,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
- File.open foo_path, 'w' do |io|
+ write_file foo_path do |io|
io.puts 'I changed it!'
end
@@ -39,15 +39,14 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal "Restoring gem(s) to pristine condition...", out.shift
+ assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
end
def test_execute_all
a = quick_spec 'a' do |s| s.executables = %w[foo] end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
+ write_file File.join(@tempdir, 'bin', 'foo') do |fp|
fp.puts "#!/usr/bin/ruby"
end
@@ -67,35 +66,106 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal "Restoring gem(s) to pristine condition...", out.shift
+ assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
end
- def test_execute_missing_cache_gem
- a = quick_spec 'a' do |s|
- s.executables = %w[foo]
+ def test_execute_no_exetension
+ a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
+
+ ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
+ write_file ext_path do |io|
+ io.write '# extconf.rb'
end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
+ util_build_gem a
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
- fp.puts "#!/usr/bin/ruby"
+ @cmd.options[:args] = %w[a]
+ @cmd.options[:extensions] = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+
+ assert_equal 'Restoring gems to pristine condition...', out.shift
+ assert_equal "Skipped #{a.full_name}, it needs to compile an extension",
+ out.shift
+ assert_empty out, out.inspect
+ end
+
+ def test_execute_many
+ a = quick_spec 'a'
+ b = quick_spec 'b'
+
+ install_gem a
+ install_gem b
+
+ @cmd.options[:args] = %w[a b]
+
+ use_ui @ui do
+ @cmd.execute
end
+ out = @ui.output.split "\n"
+
+ assert_equal "Restoring gems to pristine condition...", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
+ assert_equal "Restored #{b.full_name}", out.shift
+ assert_empty out, out.inspect
+ end
+
+ def test_execute_many_multi_repo
+ a = quick_spec 'a'
install_gem a
- a_data = nil
- open File.join(@gemhome, 'cache', a.file_name), 'rb' do |fp|
- a_data = fp.read
+ Gem.clear_paths
+ gemhome2 = File.join @tempdir, 'gemhome2'
+ Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
+
+ b = quick_spec 'b'
+ install_gem b
+
+ @cmd.options[:args] = %w[a b]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+
+ assert_equal "Restoring gems to pristine condition...", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
+ assert_equal "Restored #{b.full_name}", out.shift
+ assert_empty out, out.inspect
+
+ assert_path_exists File.join(@gemhome, "gems", 'a-2')
+ refute_path_exists File.join(gemhome2, "gems", 'a-2')
+ assert_path_exists File.join(gemhome2, "gems", 'b-2')
+ refute_path_exists File.join(@gemhome, "gems", 'b-2')
+ end
+
+ def test_execute_missing_cache_gem
+ a_2 = quick_spec 'a', 2
+ a_3 = quick_spec 'a', 3
+
+ install_gem a_2
+ install_gem a_3
+
+ a_2_data = nil
+ open File.join(@gemhome, 'cache', a_2.file_name), 'rb' do |fp|
+ a_2_data = fp.read
end
util_setup_fake_fetcher
- util_setup_spec_fetcher a
+ util_setup_spec_fetcher a_2
- Gem::RemoteFetcher.fetcher.data["http://gems.example.com/gems/#{a.file_name}"] = a_data
+ url = "http://gems.example.com/gems/#{a_2.file_name}"
+ Gem::RemoteFetcher.fetcher.data[url] = a_2_data
- FileUtils.rm Gem.cache_gem(a.file_name, @gemhome)
+ FileUtils.rm a_2.cache_file
@cmd.options[:args] = %w[a]
@@ -106,11 +176,12 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
[
- "Restoring gem\(s\) to pristine condition...",
+ "Restoring gems to pristine condition...",
"Restored a-1",
"Cached gem for a-2 not found, attempting to fetch...",
"Restored a-2",
- "Restored a-3.a"
+ "Restored a-3.a",
+ "Restored a-3",
].each do |line|
assert_equal line, out.shift
end
@@ -127,7 +198,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
end
- assert_match %r|specify a gem name|, e.message
+ assert_match %r|at least one gem name|, e.message
end
end