Skip to content

Commit

Permalink
Test Gem::SpecFetcher#load_specs
Browse files Browse the repository at this point in the history
git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1755 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information
drbrain committed Jun 8, 2008
1 parent 48af6f8 commit 9619a73
Showing 1 changed file with 44 additions and 38 deletions.
82 changes: 44 additions & 38 deletions test/test_gem_spec_fetcher.rb
Expand Up @@ -13,14 +13,14 @@ def setup

@source_index.add_spec @pl1

@specs = @source_index.map do |name, spec|
@specs = @source_index.gems.sort.map do |name, spec|
[spec.name, spec.version, spec.original_platform]
end
end.sort

@fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
util_gzip(Marshal.dump(@specs))

@latest_specs = @source_index.latest_specs.map do |spec|
@latest_specs = @source_index.latest_specs.sort.map do |spec|
[spec.name, spec.version, spec.original_platform]
end

Expand Down Expand Up @@ -220,11 +220,48 @@ def test_find_all_platforms
assert_equal expected, specs
end

def test_list
specs = @sf.list

assert_equal [@uri], specs.keys
assert_equal @latest_specs, specs[@uri].sort
end

def test_list_all
specs = @sf.list true

assert_equal [@uri], specs.keys

assert_equal @specs, specs[@uri].sort
end

def test_list_cache
specs = @sf.list

assert !specs[@uri].empty?

@fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil

cached_specs = @sf.list

assert_equal specs, cached_specs
end

def test_list_cache_all
specs = @sf.list true

assert !specs[@uri].empty?

@fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil

cached_specs = @sf.list true

assert_equal specs, cached_specs
end

def test_load_specs
specs = @sf.load_specs @uri, 'specs'

expected = [
['a', Gem::Version.new(1), Gem::Platform::RUBY],
['a', Gem::Version.new(2), Gem::Platform::RUBY],
Expand All @@ -233,7 +270,7 @@ def test_list_all
['pl', Gem::Version.new(1), 'i386-linux'],
]

assert_equal expected, specs[@uri].sort
assert_equal expected, specs

cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com:80'
assert File.exist?(cache_dir)
Expand All @@ -242,17 +279,7 @@ def test_list_all
assert File.exist?(cache_file)
end

def test_list_cache
specs = @sf.list

assert !specs[@uri].empty?

@fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil

specs = @sf.list
end

def test_list_disk_cache
def test_load_specs_cached
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
' ' * Marshal.dump(@latest_specs).length
Expand All @@ -267,30 +294,9 @@ def test_list_disk_cache
Marshal.dump @latest_specs, io
end

specs = @sf.list

assert !specs[@uri].empty?
end
specs = @sf.load_specs @uri, 'specs'

def test_list_latest
specs = @sf.list

assert_equal [@uri], specs.keys

expected = [
['a', Gem::Version.new(2), Gem::Platform::RUBY],
['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
['pl', Gem::Version.new(1), 'i386-linux'],
]

assert_equal expected, specs[@uri].sort

cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com:80'
assert File.exist?(cache_dir)

cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
assert File.exist?(cache_file)
assert_equal @specs, specs
end

end
Expand Down

0 comments on commit 9619a73

Please sign in to comment.