Change soft-fail to use the config, rather than env
[rbx.git] / test / rubygems / test_gem_source_info_cache_entry.rb
blob6986c9cd7f4da1f69249dd94570693446dbb5a7a
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     assert_equal [], sic_e.source_index.map { |n,| n }
45     use_ui @ui do
46       assert sic_e.refresh(@gem_repo, false)
47     end
49     assert_equal [a2_name], sic_e.source_index.map { |n,| n }.sort
51     use_ui @ui do
52       sic_e.refresh @gem_repo, true
53     end
55     assert_equal [a1_name, a2_name], sic_e.source_index.map { |n,| n }.sort
56   end
58   def test_refresh_bad_uri
59     assert_raise URI::BadURIError do
60       @sic_e.refresh 'gems.example.com', true
61     end
62   end
64   def test_refresh_update
65     si = Gem::SourceIndex.new
66     si.add_spec @a1
67     si.add_spec @b2
68     @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
70     use_ui @ui do
71       @sic_e.refresh @gem_repo, true
72     end
74     new_gem = @sic_e.source_index.specification(@b2.full_name)
75     assert_equal @b2.full_name, new_gem.full_name
76   end
78 end