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 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
19 @fetcher.data["#{@gem_repo}/gems/#{@a1.full_name}.gem"] = read_binary @a1_path
20 @fetcher.data["#{@gem_repo}/gems/#{@a2.full_name}.gem"] = read_binary @a2_path
26 Gem::Installer.new(@a1_path).install
28 @cmd.options[:args] = []
34 out = @ui.output.split "\n"
35 assert_equal "Updating installed gems", out.shift
36 assert_match %r|Bulk updating|, out.shift
37 assert_equal "Updating #{@a2.name}", out.shift
38 assert_equal "Successfully installed #{@a2.full_name}", out.shift
39 assert_equal "Gems updated: #{@a2.name}", out.shift
41 assert out.empty?, out.inspect
47 # a2 -> b2 # new dependency
50 def test_execute_dependencies
51 @a1.add_dependency 'c', '1.2'
53 @c2 = quick_gem 'c', '2' do |s|
54 s.files = %w[lib/code.rb]
55 s.require_paths = %w[lib]
58 @a2.add_dependency 'c', '2'
59 @a2.add_dependency 'b', '2'
61 @b2_path = File.join @gemhome, 'cache', "#{@b2.full_name}.gem"
62 @c1_2_path = File.join @gemhome, 'cache', "#{@c1_2.full_name}.gem"
63 @c2_path = File.join @gemhome, 'cache', "#{@c2.full_name}.gem"
65 @source_index = Gem::SourceIndex.new
66 @source_index.add_spec @a1
67 @source_index.add_spec @a2
68 @source_index.add_spec @b2
69 @source_index.add_spec @c1_2
70 @source_index.add_spec @c2
76 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
78 @fetcher.data["#{@gem_repo}/gems/#{@a1.full_name}.gem"] = read_binary @a1_path
79 @fetcher.data["#{@gem_repo}/gems/#{@a2.full_name}.gem"] = read_binary @a2_path
80 @fetcher.data["#{@gem_repo}/gems/#{@b2.full_name}.gem"] = read_binary @b2_path
81 @fetcher.data["#{@gem_repo}/gems/#{@c1_2.full_name}.gem"] =
82 read_binary @c1_2_path
83 @fetcher.data["#{@gem_repo}/gems/#{@c2.full_name}.gem"] = read_binary @c2_path
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_match %r|Bulk updating|, out.shift
99 assert_equal "Updating #{@a2.name}", out.shift
100 assert_match %r|Bulk updating|, out.shift
101 assert_equal "Successfully installed #{@c2.full_name}", out.shift
102 assert_equal "Successfully installed #{@b2.full_name}", out.shift
103 assert_equal "Successfully installed #{@a2.full_name}", out.shift
104 assert_equal "Gems updated: #{@c2.name}, #{@b2.name}, #{@a2.name}",
107 assert out.empty?, out.inspect
110 def test_execute_named
113 Gem::Installer.new(@a1_path).install
115 @cmd.options[:args] = [@a1.name]
121 out = @ui.output.split "\n"
122 assert_equal "Updating installed gems", out.shift
123 assert_match %r|Bulk updating|, out.shift
124 assert_equal "Updating #{@a2.name}", out.shift
125 assert_equal "Successfully installed #{@a2.full_name}", out.shift
126 assert_equal "Gems updated: #{@a2.name}", out.shift
128 assert out.empty?, out.inspect
131 def test_execute_named_up_to_date
134 Gem::Installer.new(@a2_path).install
136 @cmd.options[:args] = [@a2.name]
142 out = @ui.output.split "\n"
143 assert_equal "Updating installed gems", out.shift
144 assert_match %r|Bulk updating|, out.shift
145 assert_equal "Nothing to update", out.shift
147 assert out.empty?, out.inspect
150 def test_execute_up_to_date
153 Gem::Installer.new(@a2_path).install
155 @cmd.options[:args] = []
161 out = @ui.output.split "\n"
162 assert_equal "Updating installed gems", out.shift
163 assert_match %r|Bulk updating|, out.shift
164 assert_equal "Nothing to update", out.shift
166 assert out.empty?, out.inspect
170 FileUtils.rm_r File.join(@gemhome, 'gems')
171 FileUtils.rm_r File.join(@gemhome, 'specifications')