2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/sources_command'
5 class TestGemCommandsSourcesCommand < RubyGemTestCase
10 @cmd = Gem::Commands::SourcesCommand.new
14 util_setup_source_info_cache
15 @cmd.handle_options []
22 *** CURRENT SOURCES ***
27 assert_equal expected, @ui.output
28 assert_equal '', @ui.error
32 util_setup_fake_fetcher
34 si = Gem::SourceIndex.new
37 @fetcher.data["http://beta-gems.example.com/Marshal.#{@marshal_version}"] =
40 @cmd.handle_options %w[--add http://beta-gems.example.com]
42 util_setup_source_info_cache
49 Bulk updating Gem source index for: http://beta-gems.example.com/
50 http://beta-gems.example.com added to sources
53 assert_equal expected, @ui.output
54 assert_equal '', @ui.error
56 Gem::SourceInfoCache.cache.flush
57 assert_equal %W[http://beta-gems.example.com #{@gem_repo}],
58 Gem::SourceInfoCache.cache_data.keys.sort
61 def test_execute_add_nonexistent_source
62 util_setup_fake_fetcher
64 @fetcher.data["http://beta-gems.example.com/Marshal.#{@marshal_version}"] =
66 raise Gem::RemoteFetcher::FetchError, 'it died'
69 Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
71 @cmd.handle_options %w[--add http://beta-gems.example.com]
73 util_setup_source_info_cache
80 Error fetching http://beta-gems.example.com:
84 assert_equal expected, @ui.output
85 assert_equal '', @ui.error
88 def test_execute_add_bad_uri
89 @cmd.handle_options %w[--add beta-gems.example.com]
91 util_setup_source_info_cache
98 beta-gems.example.com is not a URI
101 assert_equal expected, @ui.output
102 assert_equal '', @ui.error
105 def test_execute_clear_all
106 @cmd.handle_options %w[--clear-all]
108 util_setup_source_info_cache
110 cache = Gem::SourceInfoCache.cache
114 assert File.exist?(cache.system_cache_file),
116 assert File.exist?(cache.latest_system_cache_file),
117 'latest system cache file'
124 *** Removed user source cache ***
125 *** Removed latest user source cache ***
126 *** Removed system source cache ***
127 *** Removed latest system source cache ***
130 assert_equal expected, @ui.output
131 assert_equal '', @ui.error
133 assert !File.exist?(cache.system_cache_file),
135 assert !File.exist?(cache.latest_system_cache_file),
136 'latest system cache file'
140 def test_execute_remove
141 @cmd.handle_options %W[--remove #{@gem_repo}]
143 util_setup_source_info_cache
149 expected = "#{@gem_repo} removed from sources\n"
151 assert_equal expected, @ui.output
152 assert_equal '', @ui.error
154 Gem::SourceInfoCache.cache.flush
155 assert_equal [], Gem::SourceInfoCache.cache_data.keys
158 def test_execute_remove_no_network
159 @cmd.handle_options %W[--remove #{@gem_repo}]
161 util_setup_fake_fetcher
163 @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] = proc do
164 raise Gem::RemoteFetcher::FetchError
171 expected = "#{@gem_repo} removed from sources\n"
173 assert_equal expected, @ui.output
174 assert_equal '', @ui.error
176 Gem::SourceInfoCache.cache.flush
177 assert_equal [], Gem::SourceInfoCache.cache_data.keys
180 def test_execute_update
181 @cmd.handle_options %w[--update]
183 util_setup_source_info_cache
184 Gem::SourceInfoCache.reset
186 util_setup_fake_fetcher
187 si = Gem::SourceIndex.new
189 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
196 Bulk updating Gem source index for: #{@gem_repo}/
197 source cache successfully updated
200 assert_equal expected, @ui.output
201 assert_equal '', @ui.error