mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
b957c3dbcb
This changes "test/rubygems/test_case.rb" to "test/rubygems/helper.rb",
and "test/rubygems/test_utilities.rb" to "test/rubygems/utilities.rb".
The two files are a helper for tests, not test files. However, a file
starting with "test_" prefix is handled as a test file directly loaded
by test-unit because Rakefile specifies:
```
t.test_files = FileList['test/**/test_*.rb']
```
Directly loading test/rubygems/test_utilities.rb caused "uninitialized
constant Gem::TestCase". This issue was fixed by
59c6820971
, but the fix caused a
"circular require" warning because test_utilities.rb and test_case.rb
are now requiring each other.
Anyway, adding "test_" prefix to a test helper file is confusing, so
this changeset reverts the fix and solve the issue by renaming them.
https://github.com/rubygems/rubygems/commit/6460e018df
132 lines
2.9 KiB
Ruby
132 lines
2.9 KiB
Ruby
# frozen_string_literal: true
|
|
require_relative 'helper'
|
|
require 'rubygems/local_remote_options'
|
|
require 'rubygems/command'
|
|
|
|
class TestGemLocalRemoteOptions < Gem::TestCase
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
spec_fetcher
|
|
|
|
@cmd.add_local_remote_options
|
|
Gem.configuration.sources = nil
|
|
@cmd.handle_options %W[--clear-sources]
|
|
assert_equal Gem.default_sources, Gem.sources.to_a
|
|
end
|
|
|
|
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
|
|
|
|
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'
|
|
s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate
|
|
|
|
original_sources = Gem.sources.dup
|
|
|
|
@cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}]
|
|
|
|
original_sources << s1.to_s
|
|
original_sources << s2.to_s
|
|
original_sources << "#{s3}/"
|
|
|
|
assert_equal original_sources, Gem.sources
|
|
end
|
|
|
|
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
|
|
|
|
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'
|
|
|
|
assert_raise ArgumentError do
|
|
@cmd.handle_options %W[--source #{s1}]
|
|
end
|
|
|
|
assert_equal [@gem_repo], Gem.sources
|
|
end
|
|
end
|