2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/local_remote_options'
|
|
|
|
require 'rubygems/command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemLocalRemoteOptions < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Command.new 'dummy', 'dummy'
|
|
|
|
@cmd.extend Gem::LocalRemoteOptions
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_local_remote_options
|
|
|
|
@cmd.add_local_remote_options
|
|
|
|
|
|
|
|
args = %w[-l -r -b -B 10 --source http://gems.example.com -p --update-sources]
|
|
|
|
assert @cmd.handles?(args)
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def test_both_eh
|
|
|
|
assert_equal false, @cmd.both?
|
|
|
|
|
|
|
|
@cmd.options[:domain] = :local
|
|
|
|
|
|
|
|
assert_equal false, @cmd.both?
|
|
|
|
|
|
|
|
@cmd.options[:domain] = :both
|
|
|
|
|
|
|
|
assert_equal true, @cmd.both?
|
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
def test_clear_sources_option
|
|
|
|
@cmd.add_local_remote_options
|
|
|
|
|
|
|
|
s = URI.parse "http://only-gems.example.com/"
|
|
|
|
|
|
|
|
@cmd.handle_options %W[--clear-sources --source #{s}]
|
|
|
|
assert_equal [s.to_s], Gem.sources
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_clear_sources_option_idiot_proof
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
@cmd.add_local_remote_options
|
2018-05-30 09:01:35 -04:00
|
|
|
Gem.configuration.sources = nil
|
2011-01-18 19:08:49 -05:00
|
|
|
@cmd.handle_options %W[--clear-sources]
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal Gem.default_sources, Gem.sources.to_a
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_local_eh
|
|
|
|
assert_equal false, @cmd.local?
|
|
|
|
|
|
|
|
@cmd.options[:domain] = :local
|
|
|
|
|
|
|
|
assert_equal true, @cmd.local?
|
|
|
|
|
|
|
|
@cmd.options[:domain] = :both
|
|
|
|
|
|
|
|
assert_equal true, @cmd.local?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remote_eh
|
|
|
|
assert_equal false, @cmd.remote?
|
|
|
|
|
|
|
|
@cmd.options[:domain] = :remote
|
|
|
|
|
|
|
|
assert_equal true, @cmd.remote?
|
|
|
|
|
|
|
|
@cmd.options[:domain] = :both
|
|
|
|
|
|
|
|
assert_equal true, @cmd.remote?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_source_option
|
|
|
|
@cmd.add_source_option
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
s1 = URI.parse 'http://more-gems.example.com/'
|
|
|
|
s2 = URI.parse 'http://even-more-gems.example.com/'
|
|
|
|
s3 = URI.parse 'http://other-gems.example.com/some_subdir'
|
2009-06-09 17:38:59 -04:00
|
|
|
s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
original_sources = Gem.sources.dup
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
original_sources << s1.to_s
|
|
|
|
original_sources << s2.to_s
|
|
|
|
original_sources << "#{s3}/"
|
|
|
|
|
|
|
|
assert_equal original_sources, Gem.sources
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_short_source_option
|
|
|
|
@cmd.add_source_option
|
|
|
|
|
|
|
|
original_sources = Gem.sources.dup
|
|
|
|
|
|
|
|
source = URI.parse 'http://more-gems.example.com/'
|
|
|
|
@cmd.handle_options %W[-s #{source}]
|
|
|
|
|
|
|
|
original_sources << source
|
|
|
|
|
|
|
|
assert_equal original_sources, Gem.sources
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_update_sources_option
|
|
|
|
@cmd.add_update_sources_option
|
|
|
|
|
|
|
|
Gem.configuration.update_sources = false
|
|
|
|
|
|
|
|
@cmd.handle_options %W[--update-sources]
|
|
|
|
|
|
|
|
assert_equal true, Gem.configuration.update_sources
|
|
|
|
|
|
|
|
@cmd.handle_options %W[--no-update-sources]
|
|
|
|
|
|
|
|
assert_equal false, Gem.configuration.update_sources
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_source_option_bad
|
|
|
|
@cmd.add_source_option
|
|
|
|
|
|
|
|
s1 = 'htp://more-gems.example.com'
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise ArgumentError do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.handle_options %W[--source #{s1}]
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal [@gem_repo], Gem.sources
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|