rubygems-update 1.1.1 → 1.2.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 (152) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +267 -1
  3. data/Rakefile +13 -7
  4. data/doc/release_notes/rel_1_2_0.rdoc +105 -0
  5. data/lib/rubygems.rb +82 -14
  6. data/lib/rubygems/command.rb +1 -1
  7. data/lib/rubygems/command_manager.rb +3 -2
  8. data/lib/rubygems/commands/cert_command.rb +1 -1
  9. data/lib/rubygems/commands/dependency_command.rb +57 -19
  10. data/lib/rubygems/commands/environment_command.rb +2 -0
  11. data/lib/rubygems/commands/fetch_command.rb +3 -1
  12. data/lib/rubygems/commands/install_command.rb +3 -3
  13. data/lib/rubygems/commands/list_command.rb +30 -28
  14. data/lib/rubygems/commands/lock_command.rb +1 -1
  15. data/lib/rubygems/commands/outdated_command.rb +5 -2
  16. data/lib/rubygems/commands/pristine_command.rb +3 -44
  17. data/lib/rubygems/commands/query_command.rb +80 -21
  18. data/lib/rubygems/commands/sources_command.rb +56 -28
  19. data/lib/rubygems/commands/specification_command.rb +4 -3
  20. data/lib/rubygems/commands/stale_command.rb +27 -0
  21. data/lib/rubygems/commands/update_command.rb +35 -22
  22. data/lib/rubygems/config_file.rb +29 -12
  23. data/lib/rubygems/custom_require.rb +1 -1
  24. data/lib/rubygems/defaults.rb +1 -1
  25. data/lib/rubygems/dependency.rb +63 -9
  26. data/lib/rubygems/dependency_installer.rb +60 -23
  27. data/lib/rubygems/dependency_list.rb +1 -1
  28. data/lib/rubygems/doc_manager.rb +5 -5
  29. data/lib/rubygems/gem_openssl.rb +1 -1
  30. data/lib/rubygems/indexer.rb +269 -84
  31. data/lib/rubygems/install_update_options.rb +6 -0
  32. data/lib/rubygems/installer.rb +35 -12
  33. data/lib/rubygems/local_remote_options.rb +26 -5
  34. data/lib/rubygems/platform.rb +15 -1
  35. data/lib/rubygems/remote_fetcher.rb +158 -90
  36. data/lib/rubygems/requirement.rb +16 -12
  37. data/lib/rubygems/rubygems_version.rb +1 -1
  38. data/lib/rubygems/security.rb +2 -2
  39. data/lib/rubygems/server.rb +239 -110
  40. data/lib/rubygems/source_index.rb +44 -18
  41. data/lib/rubygems/source_info_cache.rb +1 -1
  42. data/lib/rubygems/spec_fetcher.rb +251 -0
  43. data/lib/rubygems/specification.rb +120 -38
  44. data/lib/rubygems/test_utilities.rb +120 -0
  45. data/lib/rubygems/uninstaller.rb +11 -10
  46. data/lib/rubygems/user_interaction.rb +149 -74
  47. data/lib/rubygems/validator.rb +3 -3
  48. data/lib/rubygems/version.rb +23 -21
  49. data/setup.rb +105 -100
  50. data/test/gemutilities.rb +63 -86
  51. data/test/test_config.rb +0 -5
  52. data/test/test_gem.rb +22 -2
  53. data/test/test_gem_command_manager.rb +1 -1
  54. data/test/test_gem_commands_dependency_command.rb +125 -6
  55. data/test/test_gem_commands_environment_command.rb +1 -0
  56. data/test/test_gem_commands_fetch_command.rb +24 -4
  57. data/test/test_gem_commands_install_command.rb +6 -8
  58. data/test/{test_gem_outdated_command.rb → test_gem_commands_outdated_command.rb} +5 -2
  59. data/test/test_gem_commands_pristine_command.rb +13 -4
  60. data/test/test_gem_commands_query_command.rb +113 -37
  61. data/test/test_gem_commands_sources_command.rb +101 -31
  62. data/test/test_gem_commands_specification_command.rb +4 -1
  63. data/test/test_gem_commands_stale_command.rb +39 -0
  64. data/test/test_gem_commands_update_command.rb +17 -27
  65. data/test/test_gem_config_file.rb +38 -1
  66. data/test/test_gem_dependency.rb +51 -0
  67. data/test/test_gem_dependency_installer.rb +133 -25
  68. data/test/test_gem_gem_path_searcher.rb +4 -1
  69. data/test/test_gem_indexer.rb +124 -19
  70. data/test/test_gem_installer.rb +32 -2
  71. data/test/test_gem_local_remote_options.rb +6 -5
  72. data/test/test_gem_remote_fetcher.rb +14 -9
  73. data/test/test_gem_server.rb +207 -21
  74. data/test/test_gem_source_index.rb +203 -63
  75. data/test/test_gem_source_info_cache.rb +8 -6
  76. data/test/test_gem_source_info_cache_entry.rb +11 -9
  77. data/test/test_gem_spec_fetcher.rb +303 -0
  78. data/test/test_gem_specification.rb +91 -7
  79. data/test/test_gem_uninstaller.rb +21 -0
  80. data/test/test_gem_version.rb +14 -5
  81. data/test/test_kernel.rb +1 -1
  82. metadata +10 -73
  83. metadata.gz.sig +0 -0
  84. data/lib/rubygems/indexer/abstract_index_builder.rb +0 -88
  85. data/lib/rubygems/indexer/latest_index_builder.rb +0 -35
  86. data/lib/rubygems/indexer/marshal_index_builder.rb +0 -17
  87. data/lib/rubygems/indexer/master_index_builder.rb +0 -54
  88. data/lib/rubygems/indexer/quick_index_builder.rb +0 -50
  89. data/test/gem_installer_test_case.rbc +0 -0
  90. data/test/gem_package_tar_test_case.rbc +0 -0
  91. data/test/gemutilities.rbc +0 -0
  92. data/test/mockgemui.rbc +0 -0
  93. data/test/simple_gem.rbc +0 -0
  94. data/test/test_config.rbc +0 -0
  95. data/test/test_gem.rbc +0 -0
  96. data/test/test_gem_builder.rbc +0 -0
  97. data/test/test_gem_command.rbc +0 -0
  98. data/test/test_gem_command_manager.rbc +0 -0
  99. data/test/test_gem_commands_build_command.rbc +0 -0
  100. data/test/test_gem_commands_cert_command.rbc +0 -0
  101. data/test/test_gem_commands_check_command.rbc +0 -0
  102. data/test/test_gem_commands_contents_command.rbc +0 -0
  103. data/test/test_gem_commands_dependency_command.rbc +0 -0
  104. data/test/test_gem_commands_environment_command.rbc +0 -0
  105. data/test/test_gem_commands_fetch_command.rbc +0 -0
  106. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  107. data/test/test_gem_commands_install_command.rbc +0 -0
  108. data/test/test_gem_commands_mirror_command.rbc +0 -0
  109. data/test/test_gem_commands_pristine_command.rbc +0 -0
  110. data/test/test_gem_commands_query_command.rbc +0 -0
  111. data/test/test_gem_commands_server_command.rbc +0 -0
  112. data/test/test_gem_commands_sources_command.rbc +0 -0
  113. data/test/test_gem_commands_specification_command.rbc +0 -0
  114. data/test/test_gem_commands_unpack_command.rbc +0 -0
  115. data/test/test_gem_commands_update_command.rbc +0 -0
  116. data/test/test_gem_config_file.rbc +0 -0
  117. data/test/test_gem_dependency.rbc +0 -0
  118. data/test/test_gem_dependency_installer.rbc +0 -0
  119. data/test/test_gem_dependency_list.rbc +0 -0
  120. data/test/test_gem_digest.rbc +0 -0
  121. data/test/test_gem_doc_manager.rbc +0 -0
  122. data/test/test_gem_ext_configure_builder.rbc +0 -0
  123. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  124. data/test/test_gem_ext_rake_builder.rbc +0 -0
  125. data/test/test_gem_format.rbc +0 -0
  126. data/test/test_gem_gem_path_searcher.rbc +0 -0
  127. data/test/test_gem_gem_runner.rbc +0 -0
  128. data/test/test_gem_indexer.rbc +0 -0
  129. data/test/test_gem_install_update_options.rbc +0 -0
  130. data/test/test_gem_installer.rbc +0 -0
  131. data/test/test_gem_local_remote_options.rbc +0 -0
  132. data/test/test_gem_outdated_command.rbc +0 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rbc +0 -0
  135. data/test/test_gem_package_tar_output.rbc +0 -0
  136. data/test/test_gem_package_tar_reader.rbc +0 -0
  137. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  138. data/test/test_gem_package_tar_writer.rbc +0 -0
  139. data/test/test_gem_platform.rbc +0 -0
  140. data/test/test_gem_remote_fetcher.rbc +0 -0
  141. data/test/test_gem_requirement.rbc +0 -0
  142. data/test/test_gem_server.rbc +0 -0
  143. data/test/test_gem_source_index.rbc +0 -0
  144. data/test/test_gem_source_info_cache.rbc +0 -0
  145. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  146. data/test/test_gem_specification.rbc +0 -0
  147. data/test/test_gem_stream_ui.rbc +0 -0
  148. data/test/test_gem_uninstaller.rbc +0 -0
  149. data/test/test_gem_validator.rbc +0 -0
  150. data/test/test_gem_version.rbc +0 -0
  151. data/test/test_gem_version_option.rbc +0 -0
  152. data/test/test_kernel.rbc +0 -0
@@ -36,6 +36,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
36
36
  def teardown
37
37
  super
38
38
  Gem.sources.replace @original_sources
39
+ Gem::SourceInfoCache.instance_variable_set :@cache, nil
39
40
  end
40
41
 
41
42
  def test_self_cache_refreshes
@@ -43,7 +44,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
43
44
  si = Gem::SourceIndex.new
44
45
  si.add_spec @a1
45
46
 
46
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
47
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
47
48
 
48
49
  Gem.sources.replace %W[#{@gem_repo}]
49
50
 
@@ -52,8 +53,9 @@ class TestGemSourceInfoCache < RubyGemTestCase
52
53
  assert_kind_of Gem::SourceInfoCache, Gem::SourceInfoCache.cache
53
54
  assert_equal Gem::SourceInfoCache.cache.object_id,
54
55
  Gem::SourceInfoCache.cache.object_id
55
- assert_match %r|Bulk updating|, @ui.output
56
56
  end
57
+
58
+ assert_match %r|Bulk updating|, @ui.output
57
59
  end
58
60
 
59
61
  def test_self_cache_skips_refresh_based_on_configuration
@@ -61,7 +63,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
61
63
  si = Gem::SourceIndex.new
62
64
  si.add_spec @a1
63
65
 
64
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
66
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
65
67
 
66
68
  Gem.sources.replace %w[#{@gem_repo}]
67
69
 
@@ -78,7 +80,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
78
80
  si = Gem::SourceIndex.new
79
81
  si.add_spec @a1
80
82
 
81
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
83
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
82
84
 
83
85
  Gem::SourceInfoCache.instance_variable_set :@cache, nil
84
86
  sice = Gem::SourceInfoCacheEntry.new si, 0
@@ -106,7 +108,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
106
108
  end
107
109
 
108
110
  def test_cache_data_irreparable
109
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @source_index.dump
111
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = @source_index.dump
110
112
 
111
113
  data = { @gem_repo => { 'totally' => 'borked' } }
112
114
 
@@ -399,7 +401,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
399
401
  assert_equal @gem_repo, user_cache_data.first
400
402
 
401
403
  gems = user_cache_data.last.source_index.map { |_,spec| spec.full_name }
402
- assert_equal [@a1.full_name, @a2.full_name], gems
404
+ assert_equal [@a1.full_name, @a2.full_name], gems.sort
403
405
 
404
406
  user_cache_data = read_cache(@sic.latest_user_cache_file).to_a.sort
405
407
  assert_equal 1, user_cache_data.length
@@ -15,9 +15,9 @@ class TestGemSourceInfoCacheEntry < RubyGemTestCase
15
15
  end
16
16
 
17
17
  def test_refresh
18
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] =
18
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] =
19
19
  proc { raise }
20
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @si.dump
20
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = @si.dump
21
21
 
22
22
  use_ui @ui do
23
23
  @sic_e.refresh @gem_repo, true
@@ -30,18 +30,20 @@ class TestGemSourceInfoCacheEntry < RubyGemTestCase
30
30
  a1_name = @a1.full_name
31
31
  a2_name = @a2.full_name
32
32
 
33
- @fetcher.data["#{@gem_repo}/quick/index.rz"] =
33
+ @fetcher.data["#{@gem_repo}quick/index.rz"] =
34
34
  util_zip [a1_name, a2_name].join("\n")
35
- @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name
36
- @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a1_name}.gemspec.rz"] = util_zip Marshal.dump(@a1)
37
- @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
38
- @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] =
35
+ @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = util_zip a2_name
36
+ @fetcher.data["#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a1_name}.gemspec.rz"] = util_zip Marshal.dump(@a1)
37
+ @fetcher.data["#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
38
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
39
39
  Marshal.dump @si
40
40
 
41
41
  sic_e = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
42
42
 
43
+ assert_equal [], sic_e.source_index.map { |n,| n }
44
+
43
45
  use_ui @ui do
44
- sic_e.refresh @gem_repo, false
46
+ assert sic_e.refresh(@gem_repo, false)
45
47
  end
46
48
 
47
49
  assert_equal [a2_name], sic_e.source_index.map { |n,| n }.sort
@@ -63,7 +65,7 @@ class TestGemSourceInfoCacheEntry < RubyGemTestCase
63
65
  si = Gem::SourceIndex.new
64
66
  si.add_spec @a1
65
67
  si.add_spec @b2
66
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
68
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
67
69
 
68
70
  use_ui @ui do
69
71
  @sic_e.refresh @gem_repo, true
@@ -0,0 +1,303 @@
1
+ require 'test/unit'
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3
+ require 'rubygems/spec_fetcher'
4
+
5
+ class TestGemSpecFetcher < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @uri = URI.parse @gem_repo
11
+
12
+ util_setup_fake_fetcher
13
+
14
+ @source_index.add_spec @pl1
15
+
16
+ @specs = @source_index.gems.sort.map do |name, spec|
17
+ [spec.name, spec.version, spec.original_platform]
18
+ end.sort
19
+
20
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
21
+ util_gzip(Marshal.dump(@specs))
22
+
23
+ @latest_specs = @source_index.latest_specs.sort.map do |spec|
24
+ [spec.name, spec.version, spec.original_platform]
25
+ end
26
+
27
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
28
+ util_gzip(Marshal.dump(@latest_specs))
29
+
30
+ @sf = Gem::SpecFetcher.new
31
+ end
32
+
33
+ def test_fetch_all
34
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec.rz"] =
35
+ util_zip(Marshal.dump(@a1))
36
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.full_name}.gemspec.rz"] =
37
+ util_zip(Marshal.dump(@a2))
38
+
39
+ dep = Gem::Dependency.new 'a', 1
40
+ specs_and_sources = @sf.fetch dep, true
41
+
42
+ spec_names = specs_and_sources.map do |spec, source_uri|
43
+ [spec.full_name, source_uri]
44
+ end
45
+
46
+ expected = [[@a1.full_name, @gem_repo], [@a2.full_name, @gem_repo]]
47
+
48
+ assert_equal expected, spec_names
49
+
50
+ assert_same specs_and_sources.first.last, specs_and_sources.last.last
51
+ end
52
+
53
+ def test_fetch_latest
54
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec.rz"] =
55
+ util_zip(Marshal.dump(@a1))
56
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.full_name}.gemspec.rz"] =
57
+ util_zip(Marshal.dump(@a2))
58
+
59
+ dep = Gem::Dependency.new 'a', 1
60
+ specs_and_sources = @sf.fetch dep
61
+
62
+ spec_names = specs_and_sources.map do |spec, source_uri|
63
+ [spec.full_name, source_uri]
64
+ end
65
+
66
+ assert_equal [[@a2.full_name, @gem_repo]], spec_names
67
+ end
68
+
69
+ def test_fetch_legacy_repo
70
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] = nil
71
+ @fetcher.data["#{@gem_repo}yaml"] = ''
72
+ util_setup_source_info_cache @a1, @a2
73
+
74
+ dep = Gem::Dependency.new 'a', 1
75
+ specs = nil
76
+
77
+ use_ui @ui do
78
+ specs = @sf.fetch dep, true
79
+ end
80
+
81
+ expected = <<-EOF
82
+ WARNING: RubyGems 1.2+ index not found for:
83
+ \thttp://gems.example.com/
84
+
85
+ RubyGems will revert to legacy indexes degrading performance.
86
+ EOF
87
+
88
+ assert_equal expected, @ui.error
89
+
90
+ specs = specs.map { |spec, source_uri| [spec.full_name, source_uri] }
91
+
92
+ expected = [
93
+ [@a1.full_name, @gem_repo],
94
+ [@a2.full_name, @gem_repo],
95
+ ]
96
+
97
+ assert_equal expected, specs
98
+ end
99
+
100
+ def test_fetch_platform
101
+ util_set_arch 'i386-linux'
102
+
103
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
104
+ util_zip(Marshal.dump(@pl1))
105
+
106
+ dep = Gem::Dependency.new 'pl', 1
107
+ specs_and_sources = @sf.fetch dep
108
+
109
+ spec_names = specs_and_sources.map do |spec, source_uri|
110
+ [spec.full_name, source_uri]
111
+ end
112
+
113
+ assert_equal [[@pl1.full_name, @gem_repo]], spec_names
114
+ end
115
+
116
+ def test_fetch_spec
117
+ spec_uri = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec"
118
+ @fetcher.data["#{spec_uri}.rz"] = util_zip(Marshal.dump(@a1))
119
+
120
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
121
+ assert_equal @a1.full_name, spec.full_name
122
+
123
+ cache_dir = @sf.cache_dir URI.parse(spec_uri)
124
+
125
+ cache_file = File.join cache_dir, "#{@a1.full_name}.gemspec"
126
+
127
+ assert File.exist?(cache_file)
128
+ end
129
+
130
+ def test_fetch_spec_cached
131
+ spec_uri = "#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec"
132
+ @fetcher.data["#{spec_uri}.rz"] = nil
133
+
134
+ cache_dir = @sf.cache_dir URI.parse(spec_uri)
135
+ FileUtils.mkdir_p cache_dir
136
+
137
+ cache_file = File.join cache_dir, "#{@a1.full_name}.gemspec"
138
+
139
+ open cache_file, 'wb' do |io|
140
+ Marshal.dump @a1, io
141
+ end
142
+
143
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
144
+ assert_equal @a1.full_name, spec.full_name
145
+ end
146
+
147
+ def test_fetch_spec_platform
148
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
149
+ util_zip(Marshal.dump(@pl1))
150
+
151
+ spec = @sf.fetch_spec ['pl', Gem::Version.new(1), 'i386-linux'], @uri
152
+
153
+ assert_equal @pl1.full_name, spec.full_name
154
+ end
155
+
156
+ def test_fetch_spec_platform_ruby
157
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec.rz"] =
158
+ util_zip(Marshal.dump(@a1))
159
+
160
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), nil], @uri
161
+ assert_equal @a1.full_name, spec.full_name
162
+
163
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), ''], @uri
164
+ assert_equal @a1.full_name, spec.full_name
165
+ end
166
+
167
+ def test_find_matching_all
168
+ dep = Gem::Dependency.new 'a', 1
169
+ specs = @sf.find_matching dep, true
170
+
171
+ expected = [
172
+ [['a', Gem::Version.new(1), Gem::Platform::RUBY], @gem_repo],
173
+ [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
174
+ ]
175
+
176
+ assert_equal expected, specs
177
+ end
178
+
179
+ def test_find_matching_latest
180
+ dep = Gem::Dependency.new 'a', 1
181
+ specs = @sf.find_matching dep
182
+
183
+ expected = [
184
+ [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
185
+ ]
186
+
187
+ assert_equal expected, specs
188
+ end
189
+
190
+ def test_find_matching_platform
191
+ util_set_arch 'i386-linux'
192
+
193
+ dep = Gem::Dependency.new 'pl', 1
194
+ specs = @sf.find_matching dep
195
+
196
+ expected = [
197
+ [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
198
+ ]
199
+
200
+ assert_equal expected, specs
201
+
202
+ util_set_arch 'i386-freebsd6'
203
+
204
+ dep = Gem::Dependency.new 'pl', 1
205
+ specs = @sf.find_matching dep
206
+
207
+ assert_equal [], specs
208
+ end
209
+
210
+ def test_find_all_platforms
211
+ util_set_arch 'i386-freebsd6'
212
+
213
+ dep = Gem::Dependency.new 'pl', 1
214
+ specs = @sf.find_matching dep, false, false
215
+
216
+ expected = [
217
+ [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
218
+ ]
219
+
220
+ assert_equal expected, specs
221
+ end
222
+
223
+ def test_list
224
+ specs = @sf.list
225
+
226
+ assert_equal [@uri], specs.keys
227
+ assert_equal @latest_specs, specs[@uri].sort
228
+ end
229
+
230
+ def test_list_all
231
+ specs = @sf.list true
232
+
233
+ assert_equal [@uri], specs.keys
234
+
235
+ assert_equal @specs, specs[@uri].sort
236
+ end
237
+
238
+ def test_list_cache
239
+ specs = @sf.list
240
+
241
+ assert !specs[@uri].empty?
242
+
243
+ @fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
244
+
245
+ cached_specs = @sf.list
246
+
247
+ assert_equal specs, cached_specs
248
+ end
249
+
250
+ def test_list_cache_all
251
+ specs = @sf.list true
252
+
253
+ assert !specs[@uri].empty?
254
+
255
+ @fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
256
+
257
+ cached_specs = @sf.list true
258
+
259
+ assert_equal specs, cached_specs
260
+ end
261
+
262
+ def test_load_specs
263
+ specs = @sf.load_specs @uri, 'specs'
264
+
265
+ expected = [
266
+ ['a', Gem::Version.new(1), Gem::Platform::RUBY],
267
+ ['a', Gem::Version.new(2), Gem::Platform::RUBY],
268
+ ['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
269
+ ['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
270
+ ['pl', Gem::Version.new(1), 'i386-linux'],
271
+ ]
272
+
273
+ assert_equal expected, specs
274
+
275
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
276
+ assert File.exist?(cache_dir), "#{cache_dir} does not exist"
277
+
278
+ cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}"
279
+ assert File.exist?(cache_file)
280
+ end
281
+
282
+ def test_load_specs_cached
283
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
284
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
285
+ ' ' * Marshal.dump(@latest_specs).length
286
+
287
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
288
+
289
+ FileUtils.mkdir_p cache_dir
290
+
291
+ cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
292
+
293
+ open cache_file, 'wb' do |io|
294
+ Marshal.dump @latest_specs, io
295
+ end
296
+
297
+ specs = @sf.load_specs @uri, 'specs'
298
+
299
+ assert_equal @specs, specs
300
+ end
301
+
302
+ end
303
+
@@ -71,6 +71,8 @@ end
71
71
  File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp|
72
72
  fp.puts "#!#{Gem.ruby}"
73
73
  end
74
+
75
+ @current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
74
76
  end
75
77
 
76
78
  def test_self_attribute_names
@@ -112,6 +114,19 @@ end
112
114
  assert_equal expected_value, actual_value
113
115
  end
114
116
 
117
+ def test_self__load_future
118
+ spec = Gem::Specification.new
119
+ spec.name = 'a'
120
+ spec.version = '1'
121
+ spec.specification_version = @current_version + 1
122
+
123
+ new_spec = Marshal.load Marshal.dump(spec)
124
+
125
+ assert_equal 'a', new_spec.name
126
+ assert_equal Gem::Version.new(1), new_spec.version
127
+ assert_equal @current_version, new_spec.specification_version
128
+ end
129
+
115
130
  def test_self_load
116
131
  spec = File.join @gemhome, 'specifications', "#{@a2.full_name}.gemspec"
117
132
  gs = Gem::Specification.load spec
@@ -213,6 +228,15 @@ end
213
228
  assert_equal 'old_platform', same_spec.original_platform
214
229
  end
215
230
 
231
+ def test_add_dependency_with_explicit_type
232
+ gem = quick_gem "awesome", "1.0" do |awesome|
233
+ awesome.add_development_dependency "monkey"
234
+ end
235
+
236
+ monkey = gem.dependencies.detect { |d| d.name == "monkey" }
237
+ assert_equal(:development, monkey.type)
238
+ end
239
+
216
240
  def test_author
217
241
  assert_equal 'A User', @a1.author
218
242
  end
@@ -282,6 +306,20 @@ end
282
306
  assert_equal [rake, jabber, pqa], @a1.dependencies
283
307
  end
284
308
 
309
+ def test_dependencies_scoped_by_type
310
+ gem = quick_gem "awesome", "1.0" do |awesome|
311
+ awesome.add_runtime_dependency "bonobo", []
312
+ awesome.add_development_dependency "monkey", []
313
+ end
314
+
315
+ bonobo = Gem::Dependency.new("bonobo", [])
316
+ monkey = Gem::Dependency.new("monkey", [], :development)
317
+
318
+ assert_equal([bonobo, monkey], gem.dependencies)
319
+ assert_equal([bonobo], gem.runtime_dependencies)
320
+ assert_equal([monkey], gem.development_dependencies)
321
+ end
322
+
285
323
  def test_description
286
324
  assert_equal 'This is a test description', @a1.description
287
325
  end
@@ -423,6 +461,15 @@ end
423
461
  @a1.full_gem_path
424
462
  end
425
463
 
464
+ def test_full_gem_path_double_slash
465
+ gemhome = @gemhome.sub(/\w\//, '\&/')
466
+ @a1.loaded_from = File.join gemhome, 'specifications',
467
+ "#{@a1.full_name}.gemspec"
468
+
469
+ assert_equal File.join(@gemhome, 'gems', @a1.full_name),
470
+ @a1.full_gem_path
471
+ end
472
+
426
473
  def test_full_name
427
474
  assert_equal 'a-1', @a1.full_name
428
475
 
@@ -531,6 +578,17 @@ end
531
578
  assert_equal ['A working computer'], @a1.requirements
532
579
  end
533
580
 
581
+ def test_runtime_dependencies_legacy
582
+ # legacy gems don't have a type
583
+ @a1.runtime_dependencies.each do |dep|
584
+ dep.instance_variable_set :@type, nil
585
+ end
586
+
587
+ expected = %w[rake jabber4r pqa]
588
+
589
+ assert_equal expected, @a1.runtime_dependencies.map { |d| d.name }
590
+ end
591
+
534
592
  def test_spaceship_name
535
593
  s1 = quick_gem 'a', '1'
536
594
  s2 = quick_gem 'b', '1'
@@ -570,6 +628,8 @@ end
570
628
  end
571
629
 
572
630
  def test_to_ruby
631
+ @a2.add_runtime_dependency 'b', '1'
632
+ @a2.dependencies.first.instance_variable_set :@type, nil
573
633
  @a2.required_rubygems_version = Gem::Requirement.new '> 0'
574
634
 
575
635
  ruby_code = @a2.to_ruby
@@ -578,8 +638,6 @@ end
578
638
  s.name = %q{a}
579
639
  s.version = \"2\"
580
640
 
581
- s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} if s.respond_to? :specification_version=
582
-
583
641
  s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
584
642
  s.authors = [\"A User\"]
585
643
  s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
@@ -591,6 +649,19 @@ end
591
649
  s.require_paths = [\"lib\"]
592
650
  s.rubygems_version = %q{#{Gem::RubyGemsVersion}}
593
651
  s.summary = %q{this is a summary}
652
+
653
+ if s.respond_to? :specification_version then
654
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
655
+ s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
656
+
657
+ if current_version >= 3 then
658
+ s.add_runtime_dependency(%q<b>, [\"= 1\"])
659
+ else
660
+ s.add_dependency(%q<b>, [\"= 1\"])
661
+ end
662
+ else
663
+ s.add_dependency(%q<b>, [\"= 1\"])
664
+ end
594
665
  end
595
666
  "
596
667
 
@@ -613,8 +684,6 @@ end
613
684
  s.version = \"1\"
614
685
  s.platform = Gem::Platform.new(#{expected_platform})
615
686
 
616
- s.specification_version = 2 if s.respond_to? :specification_version=
617
-
618
687
  s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
619
688
  s.authors = [\"A User\"]
620
689
  s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
@@ -633,9 +702,24 @@ end
633
702
  s.summary = %q{this is a summary}
634
703
  s.test_files = [\"test/suite.rb\"]
635
704
 
636
- s.add_dependency(%q<rake>, [\"> 0.4\"])
637
- s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
638
- s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
705
+ if s.respond_to? :specification_version then
706
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
707
+ s.specification_version = 2
708
+
709
+ if current_version >= 3 then
710
+ s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
711
+ s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
712
+ s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
713
+ else
714
+ s.add_dependency(%q<rake>, [\"> 0.4\"])
715
+ s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
716
+ s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
717
+ end
718
+ else
719
+ s.add_dependency(%q<rake>, [\"> 0.4\"])
720
+ s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
721
+ s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
722
+ end
639
723
  end
640
724
  "
641
725