rubygems-update 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (65) hide show
  1. data.tar.gz.sig +2 -4
  2. data/ChangeLog +155 -0
  3. data/Rakefile +20 -5
  4. data/doc/release_notes/rel_1_3_0.rdoc +125 -0
  5. data/lib/rubygems.rb +107 -15
  6. data/lib/rubygems/commands/contents_command.rb +1 -1
  7. data/lib/rubygems/commands/environment_command.rb +40 -0
  8. data/lib/rubygems/commands/help_command.rb +2 -2
  9. data/lib/rubygems/commands/install_command.rb +15 -0
  10. data/lib/rubygems/commands/lock_command.rb +15 -6
  11. data/lib/rubygems/commands/outdated_command.rb +1 -1
  12. data/lib/rubygems/commands/pristine_command.rb +1 -1
  13. data/lib/rubygems/commands/query_command.rb +14 -9
  14. data/lib/rubygems/commands/rdoc_command.rb +5 -1
  15. data/lib/rubygems/commands/specification_command.rb +2 -2
  16. data/lib/rubygems/commands/unpack_command.rb +1 -1
  17. data/lib/rubygems/commands/update_command.rb +23 -14
  18. data/lib/rubygems/commands/which_command.rb +4 -3
  19. data/lib/rubygems/config_file.rb +25 -3
  20. data/lib/rubygems/defaults.rb +42 -11
  21. data/lib/rubygems/dependency_installer.rb +19 -15
  22. data/lib/rubygems/doc_manager.rb +162 -115
  23. data/lib/rubygems/ext/builder.rb +2 -2
  24. data/lib/rubygems/ext/rake_builder.rb +1 -1
  25. data/lib/rubygems/gem_path_searcher.rb +35 -19
  26. data/lib/rubygems/indexer.rb +15 -6
  27. data/lib/rubygems/install_update_options.rb +7 -0
  28. data/lib/rubygems/installer.rb +85 -9
  29. data/lib/rubygems/local_remote_options.rb +7 -0
  30. data/lib/rubygems/package/tar_reader.rb +7 -7
  31. data/lib/rubygems/platform.rb +1 -18
  32. data/lib/rubygems/remote_fetcher.rb +45 -54
  33. data/lib/rubygems/rubygems_version.rb +1 -1
  34. data/lib/rubygems/source_index.rb +22 -7
  35. data/lib/rubygems/source_info_cache.rb +9 -0
  36. data/lib/rubygems/spec_fetcher.rb +18 -20
  37. data/lib/rubygems/specification.rb +502 -293
  38. data/lib/rubygems/test_utilities.rb +19 -8
  39. data/lib/rubygems/uninstaller.rb +60 -26
  40. data/setup.rb +15 -7
  41. data/test/gemutilities.rb +84 -0
  42. data/test/mockgemui.rb +22 -2
  43. data/test/test_gem.rb +118 -13
  44. data/test/test_gem_commands_dependency_command.rb +1 -1
  45. data/test/test_gem_commands_list_command.rb +37 -0
  46. data/test/test_gem_commands_lock_command.rb +69 -0
  47. data/test/test_gem_commands_query_command.rb +40 -1
  48. data/test/test_gem_commands_uninstall_command.rb +60 -0
  49. data/test/test_gem_config_file.rb +51 -17
  50. data/test/test_gem_ext_configure_builder.rb +9 -9
  51. data/test/test_gem_ext_rake_builder.rb +21 -12
  52. data/test/test_gem_gem_path_searcher.rb +15 -7
  53. data/test/test_gem_indexer.rb +35 -1
  54. data/test/test_gem_install_update_options.rb +26 -5
  55. data/test/test_gem_installer.rb +93 -21
  56. data/test/test_gem_local_remote_options.rb +12 -0
  57. data/test/test_gem_platform.rb +6 -13
  58. data/test/test_gem_remote_fetcher.rb +121 -31
  59. data/test/test_gem_source_index.rb +74 -21
  60. data/test/test_gem_source_info_cache.rb +2 -1
  61. data/test/test_gem_spec_fetcher.rb +13 -3
  62. data/test/test_gem_specification.rb +13 -7
  63. data/test/test_gem_uninstaller.rb +25 -2
  64. metadata +6 -2
  65. metadata.gz.sig +0 -0
@@ -5,10 +5,6 @@ require 'rubygems/gem_path_searcher'
5
5
  class Gem::GemPathSearcher
6
6
  attr_accessor :gemspecs
7
7
  attr_accessor :lib_dirs
8
-
9
- public :init_gemspecs
10
- public :matching_file
11
- public :lib_dirs_for
12
8
  end
13
9
 
14
10
  class TestGemGemPathSearcher < RubyGemTestCase
@@ -40,6 +36,10 @@ class TestGemGemPathSearcher < RubyGemTestCase
40
36
  assert_equal @foo1, @gps.find('foo')
41
37
  end
42
38
 
39
+ def test_find_all
40
+ assert_equal [@foo1], @gps.find_all('foo')
41
+ end
42
+
43
43
  def test_init_gemspecs
44
44
  assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs
45
45
  end
@@ -51,9 +51,17 @@ class TestGemGemPathSearcher < RubyGemTestCase
51
51
  assert_equal expected, lib_dirs
52
52
  end
53
53
 
54
- def test_matching_file
55
- assert !@gps.matching_file(@foo1, 'bar')
56
- assert @gps.matching_file(@foo1, 'foo')
54
+ def test_matching_file_eh
55
+ assert !@gps.matching_file?(@foo1, 'bar')
56
+ assert @gps.matching_file?(@foo1, 'foo')
57
+ end
58
+
59
+ def test_matching_files
60
+ assert_equal [], @gps.matching_files(@foo1, 'bar')
61
+
62
+ expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
63
+
64
+ assert_equal [expected], @gps.matching_files(@foo1, 'foo')
57
65
  end
58
66
 
59
67
  end
@@ -21,7 +21,6 @@ class TestGemIndexer < RubyGemTestCase
21
21
  util_make_gems
22
22
 
23
23
  @d2_0 = quick_gem 'd', '2.0'
24
- write_file File.join(*%W[gems #{@d2_0.original_name} lib code.rb]) do end
25
24
  util_build_gem @d2_0
26
25
 
27
26
  gems = File.join(@tempdir, 'gems')
@@ -38,6 +37,41 @@ class TestGemIndexer < RubyGemTestCase
38
37
  @indexer.directory
39
38
  end
40
39
 
40
+ def test_build_indicies
41
+ spec = quick_gem 'd', '2.0'
42
+ spec.instance_variable_set :@original_platform, ''
43
+
44
+ @indexer.make_temp_directories
45
+
46
+ index = Gem::SourceIndex.new
47
+ index.add_spec spec
48
+
49
+ use_ui @ui do
50
+ @indexer.build_indicies index
51
+ end
52
+
53
+ specs_path = File.join @indexer.directory, "specs.#{@marshal_version}"
54
+ specs_dump = Gem.read_binary specs_path
55
+ specs = Marshal.load specs_dump
56
+
57
+ expected = [
58
+ ['d', Gem::Version.new('2.0'), 'ruby'],
59
+ ]
60
+
61
+ assert_equal expected, specs, 'specs'
62
+
63
+ latest_specs_path = File.join @indexer.directory,
64
+ "latest_specs.#{@marshal_version}"
65
+ latest_specs_dump = Gem.read_binary latest_specs_path
66
+ latest_specs = Marshal.load latest_specs_dump
67
+
68
+ expected = [
69
+ ['d', Gem::Version.new('2.0'), 'ruby'],
70
+ ]
71
+
72
+ assert_equal expected, latest_specs, 'latest_specs'
73
+ end
74
+
41
75
  def test_generate_index
42
76
  use_ui @ui do
43
77
  @indexer.generate_index
@@ -1,20 +1,21 @@
1
1
  require 'test/unit'
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3
+ require File.join(File.expand_path(File.dirname(__FILE__)),
4
+ 'gem_installer_test_case')
3
5
  require 'rubygems/install_update_options'
4
6
  require 'rubygems/command'
5
7
 
6
- class TestGemInstallUpdateOptions < RubyGemTestCase
8
+ class TestGemInstallUpdateOptions < GemInstallerTestCase
7
9
 
8
10
  def setup
9
11
  super
10
12
 
11
13
  @cmd = Gem::Command.new 'dummy', 'dummy'
12
14
  @cmd.extend Gem::InstallUpdateOptions
15
+ @cmd.add_install_update_options
13
16
  end
14
17
 
15
18
  def test_add_install_update_options
16
- @cmd.add_install_update_options
17
-
18
19
  args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity
19
20
  --ignore-dependencies --format-exec --include-dependencies]
20
21
 
@@ -22,8 +23,6 @@ class TestGemInstallUpdateOptions < RubyGemTestCase
22
23
  end
23
24
 
24
25
  def test_security_policy
25
- @cmd.add_install_update_options
26
-
27
26
  @cmd.handle_options %w[-P HighSecurity]
28
27
 
29
28
  assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy]
@@ -37,4 +36,26 @@ class TestGemInstallUpdateOptions < RubyGemTestCase
37
36
  end
38
37
  end
39
38
 
39
+ def test_user_install_enabled
40
+ @cmd.handle_options %w[--user-install]
41
+
42
+ @installer = Gem::Installer.new @gem, @cmd.options
43
+ @installer.install
44
+ assert File.exist?(File.join(Gem.user_dir, 'gems'))
45
+ assert File.exist?(File.join(Gem.user_dir, 'gems',
46
+ @spec.full_name))
47
+ end
48
+
49
+ def test_user_install_disabled_read_only
50
+ @cmd.handle_options %w[--no-user-install]
51
+
52
+ File.chmod 0755, @userhome
53
+ FileUtils.chmod 0000, @gemhome
54
+
55
+ assert_raises(Gem::FilePermissionError) do
56
+ @installer = Gem::Installer.new @gem, @cmd.options
57
+ end
58
+ ensure
59
+ FileUtils.chmod 0755, @gemhome
60
+ end
40
61
  end
@@ -70,7 +70,10 @@ load 'my_exec'
70
70
  #{Gem.ruby}: No such file or directory -- extconf.rb (LoadError)
71
71
  EOF
72
72
 
73
- assert_equal expected, File.read(gem_make_out)
73
+ assert_match %r%#{Regexp.escape Gem.ruby} extconf.rb%,
74
+ File.read(gem_make_out)
75
+ assert_match %r%#{Regexp.escape Gem.ruby}: No such file%,
76
+ File.read(gem_make_out)
74
77
  end
75
78
 
76
79
  def test_build_extensions_unsupported
@@ -515,6 +518,7 @@ load 'my_exec'
515
518
  spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end
516
519
  gem = File.join @tempdir, "#{spec.full_name}.gem"
517
520
 
521
+ Dir.mkdir util_inst_bindir
518
522
  util_build_gem spec
519
523
  FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"),
520
524
  @tempdir
@@ -525,10 +529,23 @@ load 'my_exec'
525
529
  end
526
530
 
527
531
  def test_install
532
+ Dir.mkdir util_inst_bindir
528
533
  util_setup_gem
529
534
 
530
- use_ui @ui do
531
- assert_equal @spec, @installer.install
535
+ cache_file = File.join @gemhome, 'cache', "#{@spec.full_name}.gem"
536
+
537
+ Gem.pre_install do |installer|
538
+ assert !File.exist?(cache_file), 'cache file should not exist yet'
539
+ end
540
+
541
+ Gem.post_install do |installer|
542
+ assert File.exist?(cache_file), 'cache file should exist'
543
+ end
544
+
545
+ build_rake_in do
546
+ use_ui @ui do
547
+ assert_equal @spec, @installer.install
548
+ end
532
549
  end
533
550
 
534
551
  gemdir = File.join @gemhome, 'gems', @spec.full_name
@@ -548,6 +565,9 @@ load 'my_exec'
548
565
 
549
566
  assert_equal spec_file, @spec.loaded_from
550
567
  assert File.exist?(spec_file)
568
+
569
+ assert_same @installer, @pre_install_hook_arg
570
+ assert_same @installer, @post_install_hook_arg
551
571
  end
552
572
 
553
573
  def test_install_bad_gem
@@ -582,6 +602,29 @@ load 'my_exec'
582
602
  end
583
603
  end
584
604
 
605
+ def test_install_check_dependencies_install_dir
606
+ gemhome2 = "#{@gemhome}2"
607
+ @spec.add_dependency 'b'
608
+
609
+ b2 = quick_gem 'b', 2
610
+
611
+ FileUtils.mv @gemhome, gemhome2
612
+ Gem.source_index.gems.delete b2.full_name
613
+ source_index = Gem::SourceIndex.from_gems_in File.join(gemhome2,
614
+ 'specifications')
615
+
616
+ util_setup_gem
617
+
618
+ @installer = Gem::Installer.new @gem, :install_dir => gemhome2,
619
+ :source_index => source_index
620
+
621
+ use_ui @ui do
622
+ @installer.install
623
+ end
624
+
625
+ assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name))
626
+ end
627
+
585
628
  def test_install_force
586
629
  use_ui @ui do
587
630
  installer = Gem::Installer.new old_ruby_required, :force => true
@@ -593,12 +636,15 @@ load 'my_exec'
593
636
  end
594
637
 
595
638
  def test_install_ignore_dependencies
639
+ Dir.mkdir util_inst_bindir
596
640
  @spec.add_dependency 'b', '> 5'
597
641
  util_setup_gem
598
642
  @installer.ignore_dependencies = true
599
643
 
600
- use_ui @ui do
601
- assert_equal @spec, @installer.install
644
+ build_rake_in do
645
+ use_ui @ui do
646
+ assert_equal @spec, @installer.install
647
+ end
602
648
  end
603
649
 
604
650
  gemdir = File.join @gemhome, 'gems', @spec.full_name
@@ -635,32 +681,58 @@ load 'my_exec'
635
681
  "#{@spec.full_name}.gemspec"))
636
682
  end
637
683
 
638
- def test_install_with_message
639
- @spec.post_install_message = 'I am a shiny gem!'
684
+ unless win_platform? # File.chmod doesn't work
685
+ def test_install_user_local_fallback
686
+ Dir.mkdir util_inst_bindir
687
+ File.chmod 0755, @userhome
688
+ File.chmod 0000, util_inst_bindir
689
+ File.chmod 0000, Gem.dir
690
+ @spec.executables = ["executable"]
640
691
 
641
- use_ui @ui do
642
- Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
692
+ build_rake_in do
693
+ use_ui @ui do
694
+ util_setup_gem
695
+ @installer.install
696
+ end
697
+ end
643
698
 
644
- @installer.install
645
- end
699
+ assert File.exist?(File.join(Gem.user_dir, 'gems',
700
+ @spec.full_name, 'lib', 'code.rb'))
701
+ assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable'))
702
+ ensure
703
+ File.chmod 0755, Gem.dir
704
+ File.chmod 0755, util_inst_bindir
705
+ end
706
+
707
+ def test_install_bindir_read_only
708
+ Dir.mkdir util_inst_bindir
709
+ File.chmod 0755, @userhome
710
+ File.chmod 0000, util_inst_bindir
711
+
712
+ build_rake_in do
713
+ use_ui @ui do
714
+ setup
715
+ util_setup_gem
716
+ @installer.install
717
+ end
718
+ end
646
719
 
647
- assert_match %r|I am a shiny gem!|, @ui.output
720
+ assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable'))
721
+ ensure
722
+ File.chmod 0755, util_inst_bindir
723
+ end
648
724
  end
649
725
 
650
- def test_install_writable
651
- util_setup_gem
726
+ def test_install_with_message
727
+ @spec.post_install_message = 'I am a shiny gem!'
652
728
 
653
- orig_mode = File.stat(Gem.dir).mode
654
- File.chmod 0000, Gem.dir
729
+ use_ui @ui do
730
+ Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
655
731
 
656
- e = assert_raise Gem::FilePermissionError do
657
732
  @installer.install
658
733
  end
659
734
 
660
- assert_equal "You don't have write permissions into the #{@gemhome} directory.",
661
- e.message
662
- ensure
663
- File.chmod orig_mode, Gem.dir
735
+ assert_match %r|I am a shiny gem!|, @ui.output
664
736
  end
665
737
 
666
738
  def test_install_wrong_ruby_version
@@ -19,6 +19,18 @@ class TestGemLocalRemoteOptions < RubyGemTestCase
19
19
  assert @cmd.handles?(args)
20
20
  end
21
21
 
22
+ def test_both_eh
23
+ assert_equal false, @cmd.both?
24
+
25
+ @cmd.options[:domain] = :local
26
+
27
+ assert_equal false, @cmd.both?
28
+
29
+ @cmd.options[:domain] = :both
30
+
31
+ assert_equal true, @cmd.both?
32
+ end
33
+
22
34
  def test_local_eh
23
35
  assert_equal false, @cmd.local?
24
36
 
@@ -5,19 +5,6 @@ require 'rbconfig'
5
5
 
6
6
  class TestGemPlatform < RubyGemTestCase
7
7
 
8
- def test_self_const_missing
9
- consts = [:DARWIN, :LINUX_586, :MSWIN32, :PPC_DARWIN, :WIN32, :X86_LINUX]
10
-
11
- consts.each do |const|
12
- e = assert_raise NameError do
13
- Gem::Platform.const_missing const
14
- end
15
-
16
- assert_equal "#{const} has been removed, use CURRENT instead",
17
- e.message
18
- end
19
- end
20
-
21
8
  def test_self_local
22
9
  util_set_arch 'i686-darwin8.10.1'
23
10
 
@@ -105,6 +92,12 @@ class TestGemPlatform < RubyGemTestCase
105
92
  platform = Gem::Platform.new 'i386-mswin32-80'
106
93
 
107
94
  assert_equal expected, platform.to_a, 'i386-mswin32-80'
95
+
96
+ expected = ['x86', 'solaris', '2.10']
97
+
98
+ platform = Gem::Platform.new 'i386-solaris-2.10'
99
+
100
+ assert_equal expected, platform.to_a, 'i386-solaris-2.10'
108
101
  end
109
102
 
110
103
  def test_initialize_mswin32_vc6
@@ -10,6 +10,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
10
10
  require 'webrick'
11
11
  require 'zlib'
12
12
  require 'rubygems/remote_fetcher'
13
+ require 'ostruct'
13
14
 
14
15
  # = Testing Proxy Settings
15
16
  #
@@ -106,6 +107,8 @@ gems:
106
107
  @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
107
108
 
108
109
  Gem::RemoteFetcher.fetcher = nil
110
+
111
+ @fetcher = Gem::RemoteFetcher.fetcher
109
112
  end
110
113
 
111
114
  def test_self_fetcher
@@ -117,7 +120,10 @@ gems:
117
120
  def test_self_fetcher_with_proxy
118
121
  proxy_uri = 'http://proxy.example.com'
119
122
  Gem.configuration[:http_proxy] = proxy_uri
123
+ Gem::RemoteFetcher.fetcher = nil
124
+
120
125
  fetcher = Gem::RemoteFetcher.fetcher
126
+
121
127
  assert_not_nil fetcher
122
128
  assert_kind_of Gem::RemoteFetcher, fetcher
123
129
  assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri).to_s
@@ -145,7 +151,7 @@ gems:
145
151
  def test_fetch_size_socket_error
146
152
  fetcher = Gem::RemoteFetcher.new nil
147
153
  def fetcher.connection_for(uri)
148
- raise SocketError
154
+ raise SocketError, "tarded"
149
155
  end
150
156
 
151
157
  uri = 'http://gems.example.com/yaml'
@@ -153,15 +159,13 @@ gems:
153
159
  fetcher.fetch_size uri
154
160
  end
155
161
 
156
- assert_equal "SocketError (SocketError)\n\tfetching size (#{uri})",
157
- e.message
162
+ assert_equal "SocketError: tarded (#{uri})", e.message
158
163
  end
159
164
 
160
165
  def test_no_proxy
161
166
  use_ui @ui do
162
- fetcher = Gem::RemoteFetcher.new nil
163
- assert_data_from_server fetcher.fetch_path(@server_uri)
164
- assert_equal SERVER_DATA.size, fetcher.fetch_size(@server_uri)
167
+ assert_data_from_server @fetcher.fetch_path(@server_uri)
168
+ assert_equal SERVER_DATA.size, @fetcher.fetch_size(@server_uri)
165
169
  end
166
170
  end
167
171
 
@@ -238,6 +242,7 @@ gems:
238
242
  install_dir = File.join @tempdir, 'more_gems'
239
243
 
240
244
  a1_cache_gem = File.join install_dir, 'cache', "#{@a1.full_name}.gem"
245
+ FileUtils.mkdir_p(File.dirname(a1_cache_gem))
241
246
  actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
242
247
 
243
248
  assert_equal a1_cache_gem, actual
@@ -247,7 +252,7 @@ gems:
247
252
  assert File.exist?(a1_cache_gem)
248
253
  end
249
254
 
250
- unless win_platform? then # File.chmod doesn't work
255
+ unless win_platform? # File.chmod doesn't work
251
256
  def test_download_local_read_only
252
257
  FileUtils.mv @a1_gem, @tempdir
253
258
  local_path = File.join @tempdir, "#{@a1.full_name}.gem"
@@ -263,6 +268,19 @@ gems:
263
268
  ensure
264
269
  File.chmod 0755, File.join(@gemhome, 'cache')
265
270
  end
271
+
272
+ def test_download_read_only
273
+ File.chmod 0555, File.join(@gemhome, 'cache')
274
+ File.chmod 0555, File.join(@gemhome)
275
+
276
+ fetcher = util_fuck_with_fetcher File.read(@a1_gem)
277
+ fetcher.download(@a1, 'http://gems.example.com')
278
+ assert File.exist?(File.join(Gem.user_dir, 'cache',
279
+ "#{@a1.full_name}.gem"))
280
+ ensure
281
+ File.chmod 0755, File.join(@gemhome)
282
+ File.chmod 0755, File.join(@gemhome, 'cache')
283
+ end
266
284
  end
267
285
 
268
286
  def test_download_platform_legacy
@@ -363,10 +381,32 @@ gems:
363
381
  end
364
382
  end
365
383
 
384
+ def test_fetch_path_gzip
385
+ fetcher = Gem::RemoteFetcher.new nil
386
+
387
+ def fetcher.open_uri_or_path(uri, mtime, head = nil)
388
+ Gem.gzip 'foo'
389
+ end
390
+
391
+ assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz')
392
+ end
393
+
394
+ def test_fetch_path_gzip_unmodified
395
+ fetcher = Gem::RemoteFetcher.new nil
396
+
397
+ def fetcher.open_uri_or_path(uri, mtime, head = nil)
398
+ nil
399
+ end
400
+
401
+ assert_equal nil, fetcher.fetch_path(@uri + 'foo.gz', Time.at(0))
402
+ end
403
+
366
404
  def test_fetch_path_io_error
367
405
  fetcher = Gem::RemoteFetcher.new nil
368
406
 
369
- def fetcher.open_uri_or_path(uri) raise EOFError; end
407
+ def fetcher.open_uri_or_path(uri, mtime, head = nil)
408
+ raise EOFError
409
+ end
370
410
 
371
411
  e = assert_raise Gem::RemoteFetcher::FetchError do
372
412
  fetcher.fetch_path 'uri'
@@ -379,7 +419,9 @@ gems:
379
419
  def test_fetch_path_socket_error
380
420
  fetcher = Gem::RemoteFetcher.new nil
381
421
 
382
- def fetcher.open_uri_or_path(uri) raise SocketError; end
422
+ def fetcher.open_uri_or_path(uri, mtime, head = nil)
423
+ raise SocketError
424
+ end
383
425
 
384
426
  e = assert_raise Gem::RemoteFetcher::FetchError do
385
427
  fetcher.fetch_path 'uri'
@@ -392,7 +434,7 @@ gems:
392
434
  def test_fetch_path_system_call_error
393
435
  fetcher = Gem::RemoteFetcher.new nil
394
436
 
395
- def fetcher.open_uri_or_path(uri);
437
+ def fetcher.open_uri_or_path(uri, mtime = nil, head = nil)
396
438
  raise Errno::ECONNREFUSED, 'connect(2)'
397
439
  end
398
440
 
@@ -405,6 +447,16 @@ gems:
405
447
  assert_equal 'uri', e.uri
406
448
  end
407
449
 
450
+ def test_fetch_path_unmodified
451
+ fetcher = Gem::RemoteFetcher.new nil
452
+
453
+ def fetcher.open_uri_or_path(uri, mtime, head = nil)
454
+ nil
455
+ end
456
+
457
+ assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
458
+ end
459
+
408
460
  def test_get_proxy_from_env_empty
409
461
  orig_env_HTTP_PROXY = ENV['HTTP_PROXY']
410
462
  orig_env_http_proxy = ENV['http_proxy']
@@ -462,7 +514,7 @@ gems:
462
514
  def conn.request(req)
463
515
  unless defined? @requested then
464
516
  @requested = true
465
- res = Net::HTTPRedirection.new nil, 301, nil
517
+ res = Net::HTTPMovedPermanently.new nil, 301, nil
466
518
  res.add_field 'Location', 'http://gems.example.com/real_path'
467
519
  res
468
520
  else
@@ -475,9 +527,9 @@ gems:
475
527
  conn = { 'gems.example.com:80' => conn }
476
528
  fetcher.instance_variable_set :@connections, conn
477
529
 
478
- fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect' do |io|
479
- assert_equal 'real_path', io.read
480
- end
530
+ data = fetcher.open_uri_or_path 'http://gems.example.com/redirect'
531
+
532
+ assert_equal 'real_path', data
481
533
  end
482
534
 
483
535
  def test_open_uri_or_path_limited_redirects
@@ -486,7 +538,7 @@ gems:
486
538
  conn = Object.new
487
539
  def conn.started?() true end
488
540
  def conn.request(req)
489
- res = Net::HTTPRedirection.new nil, 301, nil
541
+ res = Net::HTTPMovedPermanently.new nil, 301, nil
490
542
  res.add_field 'Location', 'http://gems.example.com/redirect'
491
543
  res
492
544
  end
@@ -495,29 +547,43 @@ gems:
495
547
  fetcher.instance_variable_set :@connections, conn
496
548
 
497
549
  e = assert_raise Gem::RemoteFetcher::FetchError do
498
- fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect'
550
+ fetcher.open_uri_or_path 'http://gems.example.com/redirect'
499
551
  end
500
552
 
501
553
  assert_equal 'too many redirects (http://gems.example.com/redirect)',
502
554
  e.message
503
555
  end
504
556
 
505
- def test_zip
506
- use_ui @ui do
507
- self.class.enable_zip = true
508
- fetcher = Gem::RemoteFetcher.new nil
509
- assert_equal SERVER_DATA.size, fetcher.fetch_size(@server_uri), "probably not from proxy"
510
- zip_data = fetcher.fetch_path(@server_z_uri)
511
- assert zip_data.size < SERVER_DATA.size, "Zipped data should be smaller"
512
- end
557
+ def test_request
558
+ uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
559
+ util_stub_connection_for :body => :junk, :code => 200
560
+
561
+ response = @fetcher.request uri, Net::HTTP::Get
562
+
563
+ assert_equal 200, response.code
564
+ assert_equal :junk, response.body
513
565
  end
514
566
 
515
- def test_no_zip
516
- use_ui @ui do
517
- self.class.enable_zip = false
518
- fetcher = Gem::RemoteFetcher.new nil
519
- assert_error { fetcher.fetch_path(@server_z_uri) }
520
- end
567
+ def test_request_head
568
+ uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
569
+ util_stub_connection_for :body => '', :code => 200
570
+ response = @fetcher.request uri, Net::HTTP::Head
571
+
572
+ assert_equal 200, response.code
573
+ assert_equal '', response.body
574
+ end
575
+
576
+ def test_request_unmodifed
577
+ uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
578
+ conn = util_stub_connection_for :body => '', :code => 304
579
+
580
+ t = Time.now
581
+ response = @fetcher.request uri, Net::HTTP::Head, t
582
+
583
+ assert_equal 304, response.code
584
+ assert_equal '', response.body
585
+
586
+ assert_equal t.rfc2822, conn.payload['if-modified-since']
521
587
  end
522
588
 
523
589
  def test_yaml_error_on_size
@@ -528,7 +594,17 @@ gems:
528
594
  end
529
595
  end
530
596
 
531
- private
597
+ def util_stub_connection_for hash
598
+ def @fetcher.connection= conn
599
+ @conn = conn
600
+ end
601
+
602
+ def @fetcher.connection_for uri
603
+ @conn
604
+ end
605
+
606
+ @fetcher.connection = Conn.new OpenStruct.new(hash)
607
+ end
532
608
 
533
609
  def assert_error(exception_class=Exception)
534
610
  got_exception = false
@@ -548,6 +624,20 @@ gems:
548
624
  assert_block("Data is not from proxy") { data =~ /0\.4\.2/ }
549
625
  end
550
626
 
627
+ class Conn
628
+ attr_accessor :payload
629
+
630
+ def initialize(response)
631
+ @response = response
632
+ self.payload = nil
633
+ end
634
+
635
+ def request(req)
636
+ self.payload = req
637
+ @response
638
+ end
639
+ end
640
+
551
641
  class NilLog < WEBrick::Log
552
642
  def log(level, data) #Do nothing
553
643
  end