summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_spec_fetcher.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_spec_fetcher.rb')
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb168
1 files changed, 101 insertions, 67 deletions
diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb
index 54e6e41..6ee1a52 100644
--- a/test/rubygems/test_gem_spec_fetcher.rb
+++ b/test/rubygems/test_gem_spec_fetcher.rb
@@ -13,43 +13,7 @@ class TestGemSpecFetcher < Gem::TestCase
@uri = URI.parse @gem_repo
@source = Gem::Source.new(@uri)
- util_setup_fake_fetcher
-
- @a_pre = new_spec 'a', '1.a'
-
- install_specs @a_pre
-
- Gem::Specification.remove_spec @b2
-
- all = Gem::Specification.map { |spec|
- Gem::NameTuple.new(spec.name, spec.version, spec.original_platform)
- }.sort
-
- @prerelease_specs, @specs = all.partition { |g| g.prerelease? }
-
- # TODO: couldn't all of this come from the fake spec fetcher?
- @latest_specs = Gem::Specification.latest_specs.sort.map { |spec|
- Gem::NameTuple.new(spec.name, spec.version, spec.original_platform)
- }
-
- v = Gem.marshal_version
- s_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@specs)))
- l_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@latest_specs)))
- p_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@prerelease_specs)))
- @fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip
- @fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip
- @fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
-
@sf = Gem::SpecFetcher.new
-
- @released = Gem::NameTuple.from_list \
- [["a", Gem::Version.new("1"), "ruby"],
- ["a", Gem::Version.new("2"), "ruby"],
- ["a_evil", Gem::Version.new("9"), "ruby"],
- ["c", Gem::Version.new("1.2"), "ruby"],
- ['dep_x', Gem::Version.new(1), 'ruby'],
- ["pl", Gem::Version.new("1"), "i386-linux"],
- ['x', Gem::Version.new(1), 'ruby']]
end
def test_initialize
@@ -86,11 +50,12 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_spec_for_dependency_all
- d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
- @fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
- @fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
- @fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
- @fetcher.data["#{d}#{@a3a.spec_name}.rz"] = util_zip(Marshal.dump(@a3a))
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', '2.a'
+ fetcher.spec 'a', 2
+ fetcher.spec 'a', '3.a'
+ end
dep = Gem::Dependency.new 'a', ">= 1"
@@ -100,7 +65,7 @@ class TestGemSpecFetcher < Gem::TestCase
[spec.full_name, source_uri]
end
- expected = [[@a1.full_name, @source], [@a2.full_name, @source]]
+ expected = [['a-1', @source], ['a-2', @source]]
assert_equal expected, spec_names
@@ -108,10 +73,11 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_spec_for_dependency_latest
- d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
- @fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
- @fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
- @fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', 2
+ fetcher.spec 'a', '3.a'
+ end
dep = Gem::Dependency.new 'a'
specs_and_sources, _ = @sf.spec_for_dependency dep
@@ -120,14 +86,15 @@ class TestGemSpecFetcher < Gem::TestCase
[spec.full_name, source_uri]
end
- assert_equal [[@a2.full_name, Gem::Source.new(@gem_repo)]], spec_names
+ assert_equal [['a-2', Gem::Source.new(@gem_repo)]],
+ spec_names
end
def test_spec_for_dependency_prerelease
- d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
- @fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
- @fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
- @fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', '1.a'
+ fetcher.spec 'a', 1
+ end
specs_and_sources, _ = @sf.spec_for_dependency dep('a', '1.a')
@@ -135,14 +102,15 @@ class TestGemSpecFetcher < Gem::TestCase
[spec.full_name, source_uri]
end
- assert_equal [[@a_pre.full_name, Gem::Source.new(@gem_repo)]], spec_names
+ assert_equal [['a-1.a', Gem::Source.new(@gem_repo)]], spec_names
end
def test_spec_for_dependency_platform
util_set_arch 'i386-linux'
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
- util_zip(Marshal.dump(@pl1))
+ spec_fetcher do |fetcher|
+ fetcher.legacy_platform
+ end
dep = Gem::Dependency.new 'pl', 1
specs_and_sources, _ = @sf.spec_for_dependency dep
@@ -151,14 +119,16 @@ class TestGemSpecFetcher < Gem::TestCase
[spec.full_name, source_uri]
end
- assert_equal [[@pl1.full_name, Gem::Source.new(@gem_repo)]], spec_names
+ assert_equal [['pl-1-x86-linux', Gem::Source.new(@gem_repo)]],
+ spec_names
end
def test_spec_for_dependency_mismatched_platform
util_set_arch 'hrpa-989'
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
- util_zip(Marshal.dump(@pl1))
+ spec_fetcher do |fetcher|
+ fetcher.legacy_platform
+ end
dep = Gem::Dependency.new 'pl', 1
specs_and_sources, errors = @sf.spec_for_dependency dep
@@ -179,11 +149,12 @@ class TestGemSpecFetcher < Gem::TestCase
Gem.sources.replace [src]
- d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
- @fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
- @fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
- @fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
- @fetcher.data["#{d}#{@a3a.spec_name}.rz"] = util_zip(Marshal.dump(@a3a))
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', '2.a'
+ fetcher.spec 'a', 2
+ fetcher.spec 'a', '3.a'
+ end
dep = Gem::Dependency.new 'a', ">= 1"
@@ -198,31 +169,70 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_available_specs_latest
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', 2
+ fetcher.spec 'a', '3.a'
+ fetcher.legacy_platform
+ end
+
specs, _ = @sf.available_specs(:latest)
assert_equal [@source], specs.keys
- assert_equal @latest_specs, specs[@source]
+
+ expected = Gem::NameTuple.from_list \
+ [['a', v(2), Gem::Platform::RUBY],
+ ['pl', v(1), 'i386-linux']]
+
+ assert_equal expected, specs[@source]
end
def test_available_specs_released
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.legacy_platform
+ end
+
specs, _ = @sf.available_specs(:released)
assert_equal [@source], specs.keys
- assert_equal @released, specs[@source]
+ expected = Gem::NameTuple.from_list \
+ [['a', v(1), Gem::Platform::RUBY],
+ ['pl', v(1), 'i386-linux']]
+
+ assert_equal expected, specs[@source]
end
def test_available_specs_complete
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', '2.a'
+ fetcher.spec 'b', 2
+ fetcher.legacy_platform
+ end
+
specs, _ = @sf.available_specs(:complete)
assert_equal [@source], specs.keys
- expected = (@prerelease_specs + @released).sort
+ expected = Gem::NameTuple.from_list \
+ [['a', v(1), Gem::Platform::RUBY],
+ ['a', v('2.a'), Gem::Platform::RUBY],
+ ['b', v(2), Gem::Platform::RUBY],
+ ['pl', v(1), 'i386-linux']]
assert_equal expected, specs[@source]
end
def test_available_specs_complete_handles_no_prerelease
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', '2.a'
+ fetcher.spec 'b', 2
+ fetcher.legacy_platform
+ end
+
v = Gem.marshal_version
@fetcher.data.delete "#{@gem_repo}prerelease_specs.#{v}.gz"
@@ -230,10 +240,19 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal [@source], specs.keys
- assert_equal @released, specs[@source]
+ expected = Gem::NameTuple.from_list \
+ [['a', v(1), Gem::Platform::RUBY],
+ ['b', v(2), Gem::Platform::RUBY],
+ ['pl', v(1), 'i386-linux']]
+
+ assert_equal expected, specs[@source]
end
def test_available_specs_cache
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ end
+
specs, _ = @sf.available_specs(:latest)
refute specs[@source].empty?
@@ -246,6 +265,13 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_available_specs_cache_released
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', '2.a'
+ fetcher.spec 'b', 2
+ fetcher.legacy_platform
+ end
+
specs, _ = @sf.available_specs(:released)
refute specs[@source].empty?
@@ -258,9 +284,17 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_available_specs_prerelease
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', '2.a'
+ end
+
specs, _ = @sf.available_specs(:prerelease)
- assert_equal @prerelease_specs, specs[@source]
+ expected = Gem::NameTuple.from_list \
+ [['a', v('2.a'), Gem::Platform::RUBY]]
+
+ assert_equal expected, specs[@source]
end
def test_available_specs_with_bad_source