Updated RubySpec submodule to 9f66d0b1.
[rbx.git] / test / rubygems / test_gem_source_info_cache_entry.rb
blobc1194e34bc7f8e1f2916da0141cacc6022e4f637
1 require 'test/unit'
2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/source_info_cache_entry'
5 class TestGemSourceInfoCacheEntry < RubyGemTestCase
7   def setup
8     super
10     util_setup_fake_fetcher
12     @si = Gem::SourceIndex.new
13     @si.add_spec @a1
14     @sic_e = Gem::SourceInfoCacheEntry.new @si, @si.dump.size
15   end
17   def test_refresh
18     @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] =
19       proc { raise }
20     @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @si.dump
22     use_ui @ui do
23       @sic_e.refresh @gem_repo, true
24     end
25   end
27   def test_refresh_all
28     @si.add_spec @a2
30     a1_name = @a1.full_name
31     a2_name = @a2.full_name
33     @fetcher.data["#{@gem_repo}/quick/index.rz"] =
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}"] =
39       Marshal.dump @si
41     sic_e = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
43     use_ui @ui do
44       sic_e.refresh @gem_repo, false
45     end
47     assert_equal [a2_name], sic_e.source_index.map { |n,| n }.sort
49     use_ui @ui do
50       sic_e.refresh @gem_repo, true
51     end
53     assert_equal [a1_name, a2_name], sic_e.source_index.map { |n,| n }.sort
54   end
56   def test_refresh_bad_uri
57     assert_raise URI::BadURIError do
58       @sic_e.refresh 'gems.example.com', true
59     end
60   end
62   def test_refresh_update
63     si = Gem::SourceIndex.new
64     si.add_spec @a1
65     si.add_spec @b2
66     @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
68     use_ui @ui do
69       @sic_e.refresh @gem_repo, true
70     end
72     new_gem = @sic_e.source_index.specification(@b2.full_name)
73     assert_equal @b2.full_name, new_gem.full_name
74   end
76 end