2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/local_remote_options'
4 require 'rubygems/command'
6 class TestGemLocalRemoteOptions < RubyGemTestCase
11 @cmd = Gem::Command.new 'dummy', 'dummy'
12 @cmd.extend Gem::LocalRemoteOptions
15 def test_add_local_remote_options
16 @cmd.add_local_remote_options
18 args = %w[-l -r -b -B 10 --source http://gems.example.com -p --update-sources]
19 assert @cmd.handles?(args)
23 assert_equal false, @cmd.local?
25 @cmd.options[:domain] = :local
27 assert_equal true, @cmd.local?
29 @cmd.options[:domain] = :both
31 assert_equal true, @cmd.local?
35 assert_equal false, @cmd.remote?
37 @cmd.options[:domain] = :remote
39 assert_equal true, @cmd.remote?
41 @cmd.options[:domain] = :both
43 assert_equal true, @cmd.remote?
46 def test_source_option
47 @cmd.add_source_option
49 s1 = URI.parse 'http://more-gems.example.com'
50 s2 = URI.parse 'http://even-more-gems.example.com'
52 @cmd.handle_options %W[--source #{s1} --source #{s2}]
54 assert_equal [s1, s2], Gem.sources
57 def test_update_sources_option
58 @cmd.add_update_sources_option
60 Gem.configuration.update_sources = false
62 @cmd.handle_options %W[--update-sources]
64 assert_equal true, Gem.configuration.update_sources
66 @cmd.handle_options %W[--no-update-sources]
68 assert_equal false, Gem.configuration.update_sources
71 def test_source_option_bad
72 @cmd.add_source_option
74 s1 = 'htp://more-gems.example.com'
76 assert_raise OptionParser::InvalidArgument do
77 @cmd.handle_options %W[--source #{s1}]
80 assert_equal %w[http://gems.example.com], Gem.sources