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/'
51 s3 = URI.parse 'http://other-gems.example.com/some_subdir'
53 @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3}]
55 assert_equal [s1.to_s, s2.to_s, "#{s3}/"], Gem.sources
58 def test_update_sources_option
59 @cmd.add_update_sources_option
61 Gem.configuration.update_sources = false
63 @cmd.handle_options %W[--update-sources]
65 assert_equal true, Gem.configuration.update_sources
67 @cmd.handle_options %W[--no-update-sources]
69 assert_equal false, Gem.configuration.update_sources
72 def test_source_option_bad
73 @cmd.add_source_option
75 s1 = 'htp://more-gems.example.com'
77 assert_raise OptionParser::InvalidArgument do
78 @cmd.handle_options %W[--source #{s1}]
81 assert_equal [@gem_repo], Gem.sources