2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/update_command'
5 class TestGemCommandsUpdateCommand < RubyGemTestCase
10 @cmd = Gem::Commands::UpdateCommand.new
12 util_setup_fake_fetcher
14 @a1_path = File.join @gemhome, 'cache', "#{@a1.full_name}.gem"
15 @a2_path = File.join @gemhome, 'cache', "#{@a2.full_name}.gem"
17 util_setup_spec_fetcher @a1, @a2
19 @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] =
21 @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
28 Gem::Installer.new(@a1_path).install
30 @cmd.options[:args] = []
36 out = @ui.output.split "\n"
37 assert_equal "Updating installed gems", out.shift
38 assert_equal "Updating #{@a2.name}", out.shift
39 assert_equal "Successfully installed #{@a2.full_name}", out.shift
40 assert_equal "Gems updated: #{@a2.name}", out.shift
42 assert out.empty?, out.inspect
48 # a2 -> b2 # new dependency
51 def test_execute_dependencies
52 @a1.add_dependency 'c', '1.2'
54 @c2 = quick_gem 'c', '2' do |s|
55 s.files = %w[lib/code.rb]
56 s.require_paths = %w[lib]
59 @a2.add_dependency 'c', '2'
60 @a2.add_dependency 'b', '2'
62 @b2_path = File.join @gemhome, 'cache', "#{@b2.full_name}.gem"
63 @c1_2_path = File.join @gemhome, 'cache', "#{@c1_2.full_name}.gem"
64 @c2_path = File.join @gemhome, 'cache', "#{@c2.full_name}.gem"
66 @source_index = Gem::SourceIndex.new
67 @source_index.add_spec @a1
68 @source_index.add_spec @a2
69 @source_index.add_spec @b2
70 @source_index.add_spec @c1_2
71 @source_index.add_spec @c2
77 @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] = read_binary @a1_path
78 @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] = read_binary @a2_path
79 @fetcher.data["#{@gem_repo}gems/#{@b2.full_name}.gem"] = read_binary @b2_path
80 @fetcher.data["#{@gem_repo}gems/#{@c1_2.full_name}.gem"] =
81 read_binary @c1_2_path
82 @fetcher.data["#{@gem_repo}gems/#{@c2.full_name}.gem"] = read_binary @c2_path
84 util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
87 Gem::Installer.new(@c1_2_path).install
88 Gem::Installer.new(@a1_path).install
90 @cmd.options[:args] = []
96 out = @ui.output.split "\n"
97 assert_equal "Updating installed gems", out.shift
98 assert_equal "Updating #{@a2.name}", out.shift
99 assert_equal "Successfully installed #{@c2.full_name}", out.shift
100 assert_equal "Successfully installed #{@b2.full_name}", out.shift
101 assert_equal "Successfully installed #{@a2.full_name}", out.shift
102 assert_equal "Gems updated: #{@c2.name}, #{@b2.name}, #{@a2.name}",
105 assert out.empty?, out.inspect
108 def test_execute_named
111 Gem::Installer.new(@a1_path).install
113 @cmd.options[:args] = [@a1.name]
119 out = @ui.output.split "\n"
120 assert_equal "Updating installed gems", out.shift
121 assert_equal "Updating #{@a2.name}", out.shift
122 assert_equal "Successfully installed #{@a2.full_name}", out.shift
123 assert_equal "Gems updated: #{@a2.name}", out.shift
125 assert out.empty?, out.inspect
128 def test_execute_named_up_to_date
131 Gem::Installer.new(@a2_path).install
133 @cmd.options[:args] = [@a2.name]
139 out = @ui.output.split "\n"
140 assert_equal "Updating installed gems", out.shift
141 assert_equal "Nothing to update", out.shift
143 assert out.empty?, out.inspect
146 def test_execute_up_to_date
149 Gem::Installer.new(@a2_path).install
151 @cmd.options[:args] = []
157 out = @ui.output.split "\n"
158 assert_equal "Updating installed gems", out.shift
159 assert_equal "Nothing to update", out.shift
161 assert out.empty?, out.inspect