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

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_commands_query_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/query_command'
3
3
 
4
 
class TestGemCommandsQueryCommand < RubyGemTestCase
 
4
class TestGemCommandsQueryCommand < Gem::TestCase
5
5
 
6
6
  def setup
7
7
    super
9
9
    @cmd = Gem::Commands::QueryCommand.new
10
10
 
11
11
    util_setup_fake_fetcher
12
 
 
13
 
    @si = util_setup_spec_fetcher @a1, @a2, @pl1, @a3a
 
12
    util_clear_gems
 
13
    util_setup_spec_fetcher @a1, @a2, @pl1, @a3a
14
14
 
15
15
    @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
16
16
      raise Gem::RemoteFetcher::FetchError
42
42
    @a1.platform = 'x86-linux'
43
43
    @a2.platform = 'universal-darwin'
44
44
 
45
 
    @si = util_setup_spec_fetcher @a1, @a1r, @a2, @b2, @pl1
 
45
    util_clear_gems
 
46
    util_setup_spec_fetcher @a1, @a1r, @a2, @b2, @pl1
46
47
 
47
48
    @cmd.handle_options %w[-r -a]
48
49
 
64
65
  end
65
66
 
66
67
  def test_execute_all
67
 
    a1_name = @a1.full_name
68
 
    a2_name = @a2.full_name
69
 
 
70
68
    @cmd.handle_options %w[-r --all]
71
69
 
72
70
    use_ui @ui do
86
84
  end
87
85
 
88
86
  def test_execute_all_prerelease
89
 
    a1_name = @a1.full_name
90
 
    a2_name = @a2.full_name
91
 
 
92
87
    @cmd.handle_options %w[-r --all --prerelease]
93
88
 
94
89
    use_ui @ui do
113
108
    @a2.homepage = 'http://a.example.com/'
114
109
    @a2.rubyforge_project = 'rubygems'
115
110
 
116
 
    @si = util_setup_spec_fetcher @a1, @a2, @pl1
 
111
    util_clear_gems
 
112
    util_setup_spec_fetcher @a1, @a2, @pl1
117
113
 
118
114
    @cmd.handle_options %w[-r -d]
119
115
 
154
150
    @a2.rubyforge_project = 'rubygems'
155
151
    @a2.platform = 'universal-darwin'
156
152
 
157
 
    @si = util_setup_spec_fetcher @a1, @a2, @pl1
 
153
    util_clear_gems
 
154
    util_setup_spec_fetcher @a1, @a2, @pl1
158
155
 
159
156
    @cmd.handle_options %w[-r -d]
160
157
 
190
187
  end
191
188
 
192
189
  def test_execute_installed
193
 
    @cmd.handle_options %w[-n c --installed]
 
190
    @cmd.handle_options %w[-n a --installed]
194
191
 
195
 
    e = assert_raises Gem::SystemExitException do
 
192
    assert_raises Gem::MockGemUi::SystemExitException do
196
193
      use_ui @ui do
197
194
        @cmd.execute
198
195
      end
199
196
    end
200
197
 
201
 
    assert_equal 0, e.exit_code
202
 
 
203
198
    assert_equal "true\n", @ui.output
204
 
 
205
199
    assert_equal '', @ui.error
206
200
  end
207
201
 
208
202
  def test_execute_installed_no_name
209
203
    @cmd.handle_options %w[--installed]
210
204
 
211
 
    e = assert_raises Gem::SystemExitException do
 
205
    e = assert_raises Gem::MockGemUi::TermError do
212
206
      use_ui @ui do
213
207
        @cmd.execute
214
208
      end
223
217
  def test_execute_installed_not_installed
224
218
    @cmd.handle_options %w[-n not_installed --installed]
225
219
 
226
 
    e = assert_raises Gem::SystemExitException do
 
220
    e = assert_raises Gem::MockGemUi::TermError do
227
221
      use_ui @ui do
228
222
        @cmd.execute
229
223
      end
236
230
  end
237
231
 
238
232
  def test_execute_installed_version
239
 
    @cmd.handle_options %w[-n c --installed --version 1.2]
 
233
    @cmd.handle_options %w[-n a --installed --version 2]
240
234
 
241
 
    e = assert_raises Gem::SystemExitException do
 
235
    assert_raises Gem::MockGemUi::SystemExitException do
242
236
      use_ui @ui do
243
237
        @cmd.execute
244
238
      end
246
240
 
247
241
    assert_equal "true\n", @ui.output
248
242
    assert_equal '', @ui.error
249
 
 
250
 
    assert_equal 0, e.exit_code
251
243
  end
252
244
 
253
245
  def test_execute_installed_version_not_installed
254
246
    @cmd.handle_options %w[-n c --installed --version 2]
255
247
 
256
 
    e = assert_raises Gem::SystemExitException do
 
248
    e = assert_raises Gem::MockGemUi::TermError do
257
249
      use_ui @ui do
258
250
        @cmd.execute
259
251
      end
265
257
    assert_equal 1, e.exit_code
266
258
  end
267
259
 
268
 
  def test_execute_local_details
269
 
    @a3a.summary = 'This is a lot of text. ' * 4
270
 
    @a3a.authors = ['Abraham Lincoln', 'Hirohito']
271
 
    @a3a.homepage = 'http://a.example.com/'
272
 
    @a3a.rubyforge_project = 'rubygems'
273
 
 
274
 
    @cmd.handle_options %w[--local --details]
275
 
 
276
 
    use_ui @ui do
277
 
      @cmd.execute
278
 
    end
279
 
 
280
 
    expected = <<-EOF
281
 
 
282
 
*** LOCAL GEMS ***
283
 
 
284
 
a (3.a, 2, 1)
285
 
    Author: A User
286
 
    Homepage: http://example.com
287
 
    Installed at (3.a): #{@gemhome}
288
 
                 (2): #{@gemhome}
289
 
                 (1): #{@gemhome}
290
 
 
291
 
    this is a summary
292
 
 
293
 
a_evil (9)
294
 
    Author: A User
295
 
    Homepage: http://example.com
296
 
    Installed at: #{@gemhome}
297
 
 
298
 
    this is a summary
299
 
 
300
 
b (2)
301
 
    Author: A User
302
 
    Homepage: http://example.com
303
 
    Installed at: #{@gemhome}
304
 
 
305
 
    this is a summary
306
 
 
307
 
c (1.2)
308
 
    Author: A User
309
 
    Homepage: http://example.com
310
 
    Installed at: #{@gemhome}
311
 
 
312
 
    this is a summary
313
 
 
314
 
pl (1)
315
 
    Platform: i386-linux
316
 
    Author: A User
317
 
    Homepage: http://example.com
318
 
    Installed at: #{@gemhome}
319
 
 
320
 
    this is a summary
321
 
    EOF
322
 
 
323
 
    assert_equal expected, @ui.output
324
 
    assert_equal '', @ui.error
325
 
  end
326
 
 
327
260
  def test_execute_local_notty
328
261
    @cmd.handle_options %w[]
329
262
 
335
268
 
336
269
    expected = <<-EOF
337
270
a (3.a, 2, 1)
338
 
a_evil (9)
339
 
b (2)
340
 
c (1.2)
341
271
pl (1 i386-linux)
342
272
    EOF
343
273
 
412
342
*** LOCAL GEMS ***
413
343
 
414
344
a (3.a, 2, 1)
415
 
a_evil (9)
416
 
b (2)
417
 
c (1.2)
418
345
pl (1 i386-linux)
419
346
    EOF
420
347