1
require 'rubygems/test_case'
2
require 'rubygems/commands/update_command'
10
class TestGemCommandsUpdateCommand < Gem::TestCase
15
@cmd = Gem::Commands::UpdateCommand.new
17
@cmd.options[:generate_rdoc] = false
18
@cmd.options[:generate_ri] = false
20
util_setup_fake_fetcher
22
util_setup_spec_fetcher @a1, @a2
24
@a1_path = @a1.cache_file
25
@a2_path = @a2.cache_file
27
@fetcher.data["#{@gem_repo}gems/#{File.basename @a1_path}"] =
29
@fetcher.data["#{@gem_repo}gems/#{File.basename @a2_path}"] =
36
Gem::Installer.new(@a1_path).install
38
@cmd.options[:args] = []
39
@cmd.options[:generate_rdoc] = false
40
@cmd.options[:generate_ri] = false
46
out = @ui.output.split "\n"
47
assert_equal "Updating installed gems", out.shift
48
assert_equal "Updating #{@a2.name}", out.shift
49
assert_equal "Successfully installed #{@a2.full_name}", out.shift
50
assert_equal "Gems updated: #{@a2.name}", out.shift
54
def util_setup_rubygem version
55
gem = quick_spec('rubygems-update', version.to_s) do |s|
56
s.files = %w[setup.rb]
58
write_file File.join(*%W[gems #{gem.original_name} setup.rb])
60
util_setup_spec_fetcher gem
64
def util_setup_rubygem8
65
@rubygem8 = util_setup_rubygem 8
68
def util_setup_rubygem9
69
@rubygem9 = util_setup_rubygem 9
72
def util_setup_rubygem_current
73
@rubygem_current = util_setup_rubygem Gem::VERSION
76
def util_add_to_fetcher *specs
78
gem_file = spec.cache_file
79
file_name = File.basename gem_file
81
@fetcher.data["http://gems.example.com/gems/#{file_name}"] =
82
Gem.read_binary gem_file
86
def test_execute_system
89
util_setup_spec_fetcher @rubygem9
90
util_add_to_fetcher @rubygem9
92
@cmd.options[:args] = []
93
@cmd.options[:system] = true
94
@cmd.options[:generate_rdoc] = false
95
@cmd.options[:generate_ri] = false
101
out = @ui.output.split "\n"
102
assert_equal "Updating rubygems-update", out.shift
103
assert_equal "Successfully installed rubygems-update-9", out.shift
104
assert_equal "Installing RubyGems 9", out.shift
105
assert_equal "RubyGems system software updated", out.shift
110
def test_execute_system_at_latest
112
util_setup_rubygem_current
113
util_setup_spec_fetcher @rubygem_current
114
util_add_to_fetcher @rubygem_current
116
@cmd.options[:args] = []
117
@cmd.options[:system] = true
118
@cmd.options[:generate_rdoc] = false
119
@cmd.options[:generate_ri] = false
121
assert_raises Gem::MockGemUi::SystemExitException do
127
out = @ui.output.split "\n"
128
assert_equal "Latest version currently installed. Aborting.", out.shift
132
def test_execute_system_multiple
136
util_setup_spec_fetcher @rubygem8, @rubygem9
137
util_add_to_fetcher @rubygem8, @rubygem9
139
@cmd.options[:args] = []
140
@cmd.options[:system] = true
141
@cmd.options[:generate_rdoc] = false
142
@cmd.options[:generate_ri] = false
148
out = @ui.output.split "\n"
149
assert_equal "Updating rubygems-update", out.shift
150
assert_equal "Successfully installed rubygems-update-9", out.shift
151
assert_equal "Installing RubyGems 9", out.shift
152
assert_equal "RubyGems system software updated", out.shift
157
def test_execute_system_specific
161
util_setup_spec_fetcher @rubygem8, @rubygem9
162
util_add_to_fetcher @rubygem8, @rubygem9
164
@cmd.options[:args] = []
165
@cmd.options[:system] = "8"
166
@cmd.options[:generate_rdoc] = false
167
@cmd.options[:generate_ri] = false
173
out = @ui.output.split "\n"
174
assert_equal "Updating rubygems-update", out.shift
175
assert_equal "Successfully installed rubygems-update-8", out.shift
176
assert_equal "Installing RubyGems 8", out.shift
177
assert_equal "RubyGems system software updated", out.shift
182
def test_execute_system_specifically_to_latest_version
186
util_setup_spec_fetcher @rubygem8, @rubygem9
187
util_add_to_fetcher @rubygem8, @rubygem9
189
@cmd.options[:args] = []
190
@cmd.options[:system] = "9"
191
@cmd.options[:generate_rdoc] = false
192
@cmd.options[:generate_ri] = false
198
out = @ui.output.split "\n"
199
assert_equal "Updating rubygems-update", out.shift
200
assert_equal "Successfully installed rubygems-update-9", out.shift
201
assert_equal "Installing RubyGems 9", out.shift
202
assert_equal "RubyGems system software updated", out.shift
207
def test_execute_system_with_gems
208
@cmd.options[:args] = %w[gem]
209
@cmd.options[:system] = true
210
@cmd.options[:generate_rdoc] = false
211
@cmd.options[:generate_ri] = false
213
assert_raises Gem::MockGemUi::TermError do
219
assert_empty @ui.output
220
assert_equal "ERROR: Gem names are not allowed with the --system option\n",
227
# a2 -> b2 # new dependency
230
def test_execute_dependencies
231
@a1.add_dependency 'c', '1.2'
233
@c2 = quick_spec 'c', '2' do |s|
234
s.files = %w[lib/code.rb]
235
s.require_paths = %w[lib]
238
@a2.add_dependency 'c', '2'
239
@a2.add_dependency 'b', '2'
241
@b2_path = @b2.cache_file
242
@c1_2_path = @c1_2.cache_file
243
@c2_path = @c2.cache_file
245
install_specs @a1, @a2, @b2, @c1_2, @c2
251
@fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] = read_binary @a1_path
252
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = read_binary @a2_path
253
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = read_binary @b2_path
254
@fetcher.data["#{@gem_repo}gems/#{@c1_2.file_name}"] = read_binary @c1_2_path
255
@fetcher.data["#{@gem_repo}gems/#{@c2.file_name}"] = read_binary @c2_path
257
util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
259
Gem::Installer.new(@c1_2_path).install
260
Gem::Installer.new(@a1_path).install
262
Gem::Specification.reset
264
@cmd.options[:args] = []
270
out = @ui.output.split "\n"
271
assert_equal "Updating installed gems", out.shift
272
assert_equal "Updating #{@a2.name}", out.shift
273
assert_equal "Successfully installed #{@c2.full_name}", out.shift
274
assert_equal "Successfully installed #{@b2.full_name}", out.shift
275
assert_equal "Successfully installed #{@a2.full_name}", out.shift
276
assert_equal "Gems updated: #{@c2.name}, #{@b2.name}, #{@a2.name}",
282
def test_execute_named
285
Gem::Installer.new(@a1_path).install
287
@cmd.options[:args] = [@a1.name]
293
out = @ui.output.split "\n"
294
assert_equal "Updating installed gems", out.shift
295
assert_equal "Updating #{@a2.name}", out.shift
296
assert_equal "Successfully installed #{@a2.full_name}", out.shift
297
assert_equal "Gems updated: #{@a2.name}", out.shift
302
def test_execute_named_up_to_date
305
Gem::Installer.new(@a2_path).install
307
@cmd.options[:args] = [@a2.name]
313
out = @ui.output.split "\n"
314
assert_equal "Updating installed gems", out.shift
315
assert_equal "Nothing to update", out.shift
320
def test_execute_up_to_date
323
Gem::Installer.new(@a2_path).install
325
@cmd.options[:args] = []
331
out = @ui.output.split "\n"
332
assert_equal "Updating installed gems", out.shift
333
assert_equal "Nothing to update", out.shift
338
def test_handle_options_system
339
@cmd.handle_options %w[--system]
342
:generate_ri => true,
346
:generate_rdoc => true,
349
assert_equal expected, @cmd.options
352
def test_handle_options_system_non_version
353
assert_raises ArgumentError do
354
@cmd.handle_options %w[--system non-version]
358
def test_handle_options_system_specific
359
@cmd.handle_options %w[--system 1.3.7]
362
:generate_ri => true,
366
:generate_rdoc => true,
369
assert_equal expected, @cmd.options