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

« back to all changes in this revision

Viewing changes to .pc/20100829-rubygems_disable_update_system.diff/test/rubygems/test_gem_commands_update_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 'rubygems/test_case'
 
2
require 'rubygems/commands/update_command'
 
3
 
 
4
begin
 
5
  gem "rdoc"
 
6
rescue Gem::LoadError
 
7
  # ignore
 
8
end
 
9
 
 
10
class TestGemCommandsUpdateCommand < Gem::TestCase
 
11
 
 
12
  def setup
 
13
    super
 
14
 
 
15
    @cmd = Gem::Commands::UpdateCommand.new
 
16
 
 
17
    @cmd.options[:generate_rdoc] = false
 
18
    @cmd.options[:generate_ri]   = false
 
19
 
 
20
    util_setup_fake_fetcher
 
21
    util_clear_gems
 
22
    util_setup_spec_fetcher @a1, @a2
 
23
 
 
24
    @a1_path = @a1.cache_file
 
25
    @a2_path = @a2.cache_file
 
26
 
 
27
    @fetcher.data["#{@gem_repo}gems/#{File.basename @a1_path}"] =
 
28
      read_binary @a1_path
 
29
    @fetcher.data["#{@gem_repo}gems/#{File.basename @a2_path}"] =
 
30
      read_binary @a2_path
 
31
  end
 
32
 
 
33
  def test_execute
 
34
    util_clear_gems
 
35
 
 
36
    Gem::Installer.new(@a1_path).install
 
37
 
 
38
    @cmd.options[:args] = []
 
39
    @cmd.options[:generate_rdoc] = false
 
40
    @cmd.options[:generate_ri]   = false
 
41
 
 
42
    use_ui @ui do
 
43
      @cmd.execute
 
44
    end
 
45
 
 
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
 
51
    assert_empty out
 
52
  end
 
53
 
 
54
  def util_setup_rubygem version
 
55
    gem = quick_spec('rubygems-update', version.to_s) do |s|
 
56
      s.files = %w[setup.rb]
 
57
    end
 
58
    write_file File.join(*%W[gems #{gem.original_name} setup.rb])
 
59
    util_build_gem gem
 
60
    util_setup_spec_fetcher gem
 
61
    gem
 
62
  end
 
63
 
 
64
  def util_setup_rubygem8
 
65
    @rubygem8 = util_setup_rubygem 8
 
66
  end
 
67
 
 
68
  def util_setup_rubygem9
 
69
    @rubygem9 = util_setup_rubygem 9
 
70
  end
 
71
 
 
72
  def util_setup_rubygem_current
 
73
    @rubygem_current = util_setup_rubygem Gem::VERSION
 
74
  end
 
75
 
 
76
  def util_add_to_fetcher *specs
 
77
    specs.each do |spec|
 
78
      gem_file = spec.cache_file
 
79
      file_name = File.basename gem_file
 
80
 
 
81
      @fetcher.data["http://gems.example.com/gems/#{file_name}"] =
 
82
        Gem.read_binary gem_file
 
83
    end
 
84
  end
 
85
 
 
86
  def test_execute_system
 
87
    util_clear_gems
 
88
    util_setup_rubygem9
 
89
    util_setup_spec_fetcher @rubygem9
 
90
    util_add_to_fetcher @rubygem9
 
91
 
 
92
    @cmd.options[:args]          = []
 
93
    @cmd.options[:system]        = true
 
94
    @cmd.options[:generate_rdoc] = false
 
95
    @cmd.options[:generate_ri]   = false
 
96
 
 
97
    use_ui @ui do
 
98
      @cmd.execute
 
99
    end
 
100
 
 
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
 
106
 
 
107
    assert_empty out
 
108
  end
 
109
 
 
110
  def test_execute_system_at_latest
 
111
    util_clear_gems
 
112
    util_setup_rubygem_current
 
113
    util_setup_spec_fetcher @rubygem_current
 
114
    util_add_to_fetcher @rubygem_current
 
115
 
 
116
    @cmd.options[:args]          = []
 
117
    @cmd.options[:system]        = true
 
118
    @cmd.options[:generate_rdoc] = false
 
119
    @cmd.options[:generate_ri]   = false
 
120
 
 
121
    assert_raises Gem::MockGemUi::SystemExitException do
 
122
      use_ui @ui do
 
123
        @cmd.execute
 
124
      end
 
125
    end
 
126
 
 
127
    out = @ui.output.split "\n"
 
128
    assert_equal "Latest version currently installed. Aborting.", out.shift
 
129
    assert_empty out
 
130
  end
 
131
 
 
132
  def test_execute_system_multiple
 
133
    util_clear_gems
 
134
    util_setup_rubygem9
 
135
    util_setup_rubygem8
 
136
    util_setup_spec_fetcher @rubygem8, @rubygem9
 
137
    util_add_to_fetcher @rubygem8, @rubygem9
 
138
 
 
139
    @cmd.options[:args]          = []
 
140
    @cmd.options[:system]        = true
 
141
    @cmd.options[:generate_rdoc] = false
 
142
    @cmd.options[:generate_ri]   = false
 
143
 
 
144
    use_ui @ui do
 
145
      @cmd.execute
 
146
    end
 
147
 
 
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
 
153
 
 
154
    assert_empty out
 
155
  end
 
156
 
 
157
  def test_execute_system_specific
 
158
    util_clear_gems
 
159
    util_setup_rubygem9
 
160
    util_setup_rubygem8
 
161
    util_setup_spec_fetcher @rubygem8, @rubygem9
 
162
    util_add_to_fetcher @rubygem8, @rubygem9
 
163
 
 
164
    @cmd.options[:args]          = []
 
165
    @cmd.options[:system]        = "8"
 
166
    @cmd.options[:generate_rdoc] = false
 
167
    @cmd.options[:generate_ri]   = false
 
168
 
 
169
    use_ui @ui do
 
170
      @cmd.execute
 
171
    end
 
172
 
 
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
 
178
 
 
179
    assert_empty out
 
180
  end
 
181
 
 
182
  def test_execute_system_specifically_to_latest_version
 
183
    util_clear_gems
 
184
    util_setup_rubygem9
 
185
    util_setup_rubygem8
 
186
    util_setup_spec_fetcher @rubygem8, @rubygem9
 
187
    util_add_to_fetcher @rubygem8, @rubygem9
 
188
 
 
189
    @cmd.options[:args]          = []
 
190
    @cmd.options[:system]        = "9"
 
191
    @cmd.options[:generate_rdoc] = false
 
192
    @cmd.options[:generate_ri]   = false
 
193
 
 
194
    use_ui @ui do
 
195
      @cmd.execute
 
196
    end
 
197
 
 
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
 
203
 
 
204
    assert_empty out
 
205
  end
 
206
 
 
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
 
212
 
 
213
    assert_raises Gem::MockGemUi::TermError do
 
214
      use_ui @ui do
 
215
        @cmd.execute
 
216
      end
 
217
    end
 
218
 
 
219
    assert_empty @ui.output
 
220
    assert_equal "ERROR:  Gem names are not allowed with the --system option\n",
 
221
                 @ui.error
 
222
  end
 
223
 
 
224
  # before:
 
225
  #   a1 -> c1.2
 
226
  # after:
 
227
  #   a2 -> b2 # new dependency
 
228
  #   a2 -> c2
 
229
 
 
230
  def test_execute_dependencies
 
231
    @a1.add_dependency 'c', '1.2'
 
232
 
 
233
    @c2 = quick_spec 'c', '2' do |s|
 
234
      s.files = %w[lib/code.rb]
 
235
      s.require_paths = %w[lib]
 
236
    end
 
237
 
 
238
    @a2.add_dependency 'c', '2'
 
239
    @a2.add_dependency 'b', '2'
 
240
 
 
241
    @b2_path   = @b2.cache_file
 
242
    @c1_2_path = @c1_2.cache_file
 
243
    @c2_path   = @c2.cache_file
 
244
 
 
245
    install_specs @a1, @a2, @b2, @c1_2, @c2
 
246
 
 
247
    util_build_gem @a1
 
248
    util_build_gem @a2
 
249
    util_build_gem @c2
 
250
 
 
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
 
256
 
 
257
    util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
 
258
 
 
259
    Gem::Installer.new(@c1_2_path).install
 
260
    Gem::Installer.new(@a1_path).install
 
261
 
 
262
    Gem::Specification.reset
 
263
 
 
264
    @cmd.options[:args] = []
 
265
 
 
266
    use_ui @ui do
 
267
      @cmd.execute
 
268
    end
 
269
 
 
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}",
 
277
                 out.shift
 
278
 
 
279
    assert_empty out
 
280
  end
 
281
 
 
282
  def test_execute_named
 
283
    util_clear_gems
 
284
 
 
285
    Gem::Installer.new(@a1_path).install
 
286
 
 
287
    @cmd.options[:args] = [@a1.name]
 
288
 
 
289
    use_ui @ui do
 
290
      @cmd.execute
 
291
    end
 
292
 
 
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
 
298
 
 
299
    assert_empty out
 
300
  end
 
301
 
 
302
  def test_execute_named_up_to_date
 
303
    util_clear_gems
 
304
 
 
305
    Gem::Installer.new(@a2_path).install
 
306
 
 
307
    @cmd.options[:args] = [@a2.name]
 
308
 
 
309
    use_ui @ui do
 
310
      @cmd.execute
 
311
    end
 
312
 
 
313
    out = @ui.output.split "\n"
 
314
    assert_equal "Updating installed gems", out.shift
 
315
    assert_equal "Nothing to update", out.shift
 
316
 
 
317
    assert_empty out
 
318
  end
 
319
 
 
320
  def test_execute_up_to_date
 
321
    util_clear_gems
 
322
 
 
323
    Gem::Installer.new(@a2_path).install
 
324
 
 
325
    @cmd.options[:args] = []
 
326
 
 
327
    use_ui @ui do
 
328
      @cmd.execute
 
329
    end
 
330
 
 
331
    out = @ui.output.split "\n"
 
332
    assert_equal "Updating installed gems", out.shift
 
333
    assert_equal "Nothing to update", out.shift
 
334
 
 
335
    assert_empty out
 
336
  end
 
337
 
 
338
  def test_handle_options_system
 
339
    @cmd.handle_options %w[--system]
 
340
 
 
341
    expected = {
 
342
      :generate_ri   => true,
 
343
      :system        => true,
 
344
      :force         => false,
 
345
      :args          => [],
 
346
      :generate_rdoc => true,
 
347
    }
 
348
 
 
349
    assert_equal expected, @cmd.options
 
350
  end
 
351
 
 
352
  def test_handle_options_system_non_version
 
353
    assert_raises ArgumentError do
 
354
      @cmd.handle_options %w[--system non-version]
 
355
    end
 
356
  end
 
357
 
 
358
  def test_handle_options_system_specific
 
359
    @cmd.handle_options %w[--system 1.3.7]
 
360
 
 
361
    expected = {
 
362
      :generate_ri   => true,
 
363
      :system        => "1.3.7",
 
364
      :force         => false,
 
365
      :args          => [],
 
366
      :generate_rdoc => true,
 
367
    }
 
368
 
 
369
    assert_equal expected, @cmd.options
 
370
  end
 
371
 
 
372
end