1
require_relative 'gemutilities'
1
require 'rubygems/test_case'
2
2
require 'rubygems/commands/install_command'
4
class TestGemCommandsInstallCommand < RubyGemTestCase
10
class TestGemCommandsInstallCommand < Gem::TestCase
14
20
def test_execute_exclude_prerelease
15
util_setup_fake_fetcher(:prerelease)
16
util_setup_spec_fetcher @a2, @a2_pre
21
util_setup_fake_fetcher :prerelease
22
util_setup_spec_fetcher
18
24
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
19
read_binary(File.join(@gemhome, 'cache', @a2.file_name))
25
read_binary(@a2.cache_file)
20
26
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
21
read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name))
27
read_binary(@a2_pre.cache_file)
23
29
@cmd.options[:args] = [@a2.name]
36
42
def test_execute_explicit_version_includes_prerelease
37
util_setup_fake_fetcher(:prerelease)
38
util_setup_spec_fetcher @a2, @a2_pre
43
util_setup_fake_fetcher :prerelease
44
util_setup_spec_fetcher
40
46
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
41
read_binary(File.join(@gemhome, 'cache', @a2.file_name))
47
read_binary(@a2.cache_file)
42
48
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
43
read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name))
49
read_binary(@a2_pre.cache_file)
45
@cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s]
51
@cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s,
52
"--no-ri", "--no-rdoc"]
46
53
assert @cmd.options[:prerelease]
47
54
assert @cmd.options[:version].satisfied_by?(@a2_pre.version)
79
86
util_setup_fake_fetcher
80
87
@cmd.options[:domain] = :local
82
FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
89
FileUtils.mv @a2.cache_file, @tempdir
85
91
@cmd.options[:args] = [@a2.name]
109
115
util_setup_fake_fetcher
110
116
@cmd.options[:user_install] = false
112
FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
118
FileUtils.mv @a2.cache_file, @tempdir
115
120
@cmd.options[:args] = [@a2.name]
118
123
orig_dir = Dir.pwd
120
File.chmod 0755, @userhome
121
File.chmod 0555, @gemhome
125
FileUtils.chmod 0755, @userhome
126
FileUtils.chmod 0555, @gemhome
123
128
Dir.chdir @tempdir
124
129
assert_raises Gem::FilePermissionError do
172
177
assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error)
180
def test_execute_nonexistent_with_hint
181
misspelled = "nonexistent_with_hint"
182
correctly_spelled = "non_existent_with_hint"
184
util_setup_fake_fetcher
185
util_setup_spec_fetcher quick_spec(correctly_spelled, '2')
187
@cmd.options[:args] = [misspelled]
190
e = assert_raises Gem::SystemExitException do
194
assert_equal 2, e.exit_code
197
expected = "ERROR: Could not find a valid gem 'nonexistent_with_hint' (>= 0) in any repository
198
ERROR: Possible alternatives: non_existent_with_hint
201
assert_equal expected, @ui.error
175
204
def test_execute_prerelease
176
util_setup_fake_fetcher(:prerelease)
205
util_setup_fake_fetcher :prerelease
177
207
util_setup_spec_fetcher @a2, @a2_pre
179
209
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
180
read_binary(File.join(@gemhome, 'cache', @a2.file_name))
210
read_binary(@a2.cache_file)
181
211
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
182
read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name))
212
read_binary(@a2_pre.cache_file)
184
214
@cmd.options[:prerelease] = true
185
215
@cmd.options[:args] = [@a2_pre.name]
200
230
@cmd.options[:generate_ri] = true
202
232
util_setup_fake_fetcher
203
util_setup_spec_fetcher @a2
233
util_setup_spec_fetcher
205
235
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
206
read_binary(File.join(@gemhome, 'cache', @a2.file_name))
236
read_binary(@a2.cache_file)
208
238
@cmd.options[:args] = [@a2.name]
230
260
util_setup_fake_fetcher
231
261
@cmd.options[:domain] = :local
233
FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
263
FileUtils.mv @a2.cache_file, @tempdir
236
FileUtils.mv File.join(@gemhome, 'cache', @b2.file_name),
265
FileUtils.mv @b2.cache_file, @tempdir
239
267
@cmd.options[:args] = [@a2.name, @b2.name]
258
286
assert out.empty?, out.inspect
289
def test_execute_conservative
290
util_setup_fake_fetcher
291
util_setup_spec_fetcher
293
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] =
294
read_binary(@b2.cache_file)
298
@cmd.options[:conservative] = true
300
@cmd.options[:args] = [@a2.name, @b2.name]
306
assert_raises Gem::SystemExitException do
314
out = @ui.output.split "\n"
315
assert_equal "", @ui.error
316
assert_equal "Successfully installed #{@b2.full_name}", out.shift
317
assert_equal "1 gem installed", out.shift
318
assert out.empty?, out.inspect