~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_commands_install_command.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require_relative 'gemutilities'
 
1
require 'rubygems/test_case'
2
2
require 'rubygems/commands/install_command'
3
3
 
4
 
class TestGemCommandsInstallCommand < RubyGemTestCase
 
4
begin
 
5
  gem "rdoc"
 
6
rescue Gem::LoadError
 
7
  # ignore
 
8
end
 
9
 
 
10
class TestGemCommandsInstallCommand < Gem::TestCase
5
11
 
6
12
  def setup
7
13
    super
12
18
  end
13
19
 
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
17
23
 
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)
22
28
 
23
29
    @cmd.options[:args] = [@a2.name]
24
30
 
34
40
  end
35
41
 
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
39
45
 
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)
44
50
 
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)
48
55
 
79
86
    util_setup_fake_fetcher
80
87
    @cmd.options[:domain] = :local
81
88
 
82
 
    FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
83
 
                 File.join(@tempdir)
 
89
    FileUtils.mv @a2.cache_file, @tempdir
84
90
 
85
91
    @cmd.options[:args] = [@a2.name]
86
92
 
109
115
    util_setup_fake_fetcher
110
116
    @cmd.options[:user_install] = false
111
117
 
112
 
    FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
113
 
                 File.join(@tempdir)
 
118
    FileUtils.mv @a2.cache_file, @tempdir
114
119
 
115
120
    @cmd.options[:args] = [@a2.name]
116
121
 
117
122
    use_ui @ui do
118
123
      orig_dir = Dir.pwd
119
124
      begin
120
 
        File.chmod 0755, @userhome
121
 
        File.chmod 0555, @gemhome
 
125
        FileUtils.chmod 0755, @userhome
 
126
        FileUtils.chmod 0555, @gemhome
122
127
 
123
128
        Dir.chdir @tempdir
124
129
        assert_raises Gem::FilePermissionError do
126
131
        end
127
132
      ensure
128
133
        Dir.chdir orig_dir
129
 
        File.chmod 0755, @gemhome
 
134
        FileUtils.chmod 0755, @gemhome
130
135
      end
131
136
    end
132
137
  end
172
177
    assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error)
173
178
  end
174
179
 
 
180
  def test_execute_nonexistent_with_hint
 
181
    misspelled = "nonexistent_with_hint"
 
182
    correctly_spelled = "non_existent_with_hint"
 
183
 
 
184
    util_setup_fake_fetcher
 
185
    util_setup_spec_fetcher quick_spec(correctly_spelled, '2')
 
186
 
 
187
    @cmd.options[:args] = [misspelled]
 
188
 
 
189
    use_ui @ui do
 
190
      e = assert_raises Gem::SystemExitException do
 
191
        @cmd.execute
 
192
      end
 
193
 
 
194
      assert_equal 2, e.exit_code
 
195
    end
 
196
 
 
197
    expected = "ERROR:  Could not find a valid gem 'nonexistent_with_hint' (>= 0) in any repository
 
198
ERROR:  Possible alternatives: non_existent_with_hint
 
199
"
 
200
 
 
201
    assert_equal expected, @ui.error
 
202
  end
 
203
 
175
204
  def test_execute_prerelease
176
 
    util_setup_fake_fetcher(:prerelease)
 
205
    util_setup_fake_fetcher :prerelease
 
206
    util_clear_gems
177
207
    util_setup_spec_fetcher @a2, @a2_pre
178
208
 
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)
183
213
 
184
214
    @cmd.options[:prerelease] = true
185
215
    @cmd.options[:args] = [@a2_pre.name]
200
230
    @cmd.options[:generate_ri] = true
201
231
 
202
232
    util_setup_fake_fetcher
203
 
    util_setup_spec_fetcher @a2
 
233
    util_setup_spec_fetcher
204
234
 
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)
207
237
 
208
238
    @cmd.options[:args] = [@a2.name]
209
239
 
230
260
    util_setup_fake_fetcher
231
261
    @cmd.options[:domain] = :local
232
262
 
233
 
    FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
234
 
                 File.join(@tempdir)
 
263
    FileUtils.mv @a2.cache_file, @tempdir
235
264
 
236
 
    FileUtils.mv File.join(@gemhome, 'cache', @b2.file_name),
237
 
                 File.join(@tempdir)
 
265
    FileUtils.mv @b2.cache_file, @tempdir
238
266
 
239
267
    @cmd.options[:args] = [@a2.name, @b2.name]
240
268
 
258
286
    assert out.empty?, out.inspect
259
287
  end
260
288
 
 
289
  def test_execute_conservative
 
290
    util_setup_fake_fetcher
 
291
    util_setup_spec_fetcher
 
292
 
 
293
    @fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] =
 
294
      read_binary(@b2.cache_file)
 
295
 
 
296
    uninstall_gem(@b2)
 
297
 
 
298
    @cmd.options[:conservative] = true
 
299
 
 
300
    @cmd.options[:args] = [@a2.name, @b2.name]
 
301
 
 
302
    use_ui @ui do
 
303
      orig_dir = Dir.pwd
 
304
      begin
 
305
        Dir.chdir @tempdir
 
306
        assert_raises Gem::SystemExitException do
 
307
          @cmd.execute
 
308
        end
 
309
      ensure
 
310
        Dir.chdir orig_dir
 
311
      end
 
312
    end
 
313
 
 
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
 
319
  end
261
320
end
262
321