mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 06:25:31 +02:00
[rubygems/rubygems] Refactor reseting RUBYGEMS_GEMDEPS
in tests
91dca11112
This commit is contained in:
parent
43aecf216e
commit
76b77d9275
Notes:
git
2021-08-31 19:07:13 +09:00
1 changed files with 133 additions and 141 deletions
|
@ -19,7 +19,6 @@ class TestGem < Gem::TestCase
|
||||||
|
|
||||||
common_installer_setup
|
common_installer_setup
|
||||||
|
|
||||||
ENV.delete 'RUBYGEMS_GEMDEPS'
|
|
||||||
@additional = %w[a b].map {|d| File.join @tempdir, d }
|
@additional = %w[a b].map {|d| File.join @tempdir, d }
|
||||||
|
|
||||||
util_remove_interrupt_command
|
util_remove_interrupt_command
|
||||||
|
@ -663,8 +662,7 @@ class TestGem < Gem::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_self_use_gemdeps
|
def test_self_use_gemdeps
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
|
with_rubygems_gemdeps('-') do
|
||||||
|
|
||||||
FileUtils.mkdir_p 'detect/a/b'
|
FileUtils.mkdir_p 'detect/a/b'
|
||||||
FileUtils.mkdir_p 'detect/a/Isolate'
|
FileUtils.mkdir_p 'detect/a/Isolate'
|
||||||
|
|
||||||
|
@ -679,8 +677,7 @@ class TestGem < Gem::TestCase
|
||||||
ensure
|
ensure
|
||||||
Dir.chdir @tempdir
|
Dir.chdir @tempdir
|
||||||
end
|
end
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_self_dir
|
def test_self_dir
|
||||||
|
@ -1690,12 +1687,12 @@ class TestGem < Gem::TestCase
|
||||||
f.puts "gem 'c'"
|
f.puts "gem 'c'"
|
||||||
end
|
end
|
||||||
|
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = path
|
with_rubygems_gemdeps(path) do
|
||||||
|
|
||||||
Gem.use_gemdeps
|
Gem.use_gemdeps
|
||||||
|
|
||||||
assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
|
assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_auto_activation_of_used_gemdeps_file
|
def test_auto_activation_of_used_gemdeps_file
|
||||||
a = util_spec "a", "1", nil, "lib/a.rb"
|
a = util_spec "a", "1", nil, "lib/a.rb"
|
||||||
|
@ -1712,14 +1709,14 @@ class TestGem < Gem::TestCase
|
||||||
f.puts "gem 'c'"
|
f.puts "gem 'c'"
|
||||||
end
|
end
|
||||||
|
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = "-"
|
with_rubygems_gemdeps("-") do
|
||||||
|
|
||||||
expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
|
expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
|
||||||
|
|
||||||
Gem.use_gemdeps
|
Gem.use_gemdeps
|
||||||
|
|
||||||
assert_equal expected_specs, loaded_spec_names
|
assert_equal expected_specs, loaded_spec_names
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }
|
BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }
|
||||||
BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
|
BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
|
||||||
|
@ -1753,8 +1750,8 @@ class TestGem < Gem::TestCase
|
||||||
install_gem c, :install_dir => path
|
install_gem c, :install_dir => path
|
||||||
|
|
||||||
ENV['GEM_PATH'] = path
|
ENV['GEM_PATH'] = path
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = "-"
|
|
||||||
|
|
||||||
|
with_rubygems_gemdeps("-") do
|
||||||
new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
||||||
new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
|
new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
|
||||||
|
|
||||||
|
@ -1777,6 +1774,7 @@ class TestGem < Gem::TestCase
|
||||||
|
|
||||||
assert_equal ["b-1", "c-1"], out - out0
|
assert_equal ["b-1", "c-1"], out - out0
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
|
def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
|
||||||
pend "Requiring bundler messes things up" if Gem.java_platform?
|
pend "Requiring bundler messes things up" if Gem.java_platform?
|
||||||
|
@ -1801,8 +1799,8 @@ class TestGem < Gem::TestCase
|
||||||
install_gem c, :install_dir => path
|
install_gem c, :install_dir => path
|
||||||
|
|
||||||
ENV['GEM_PATH'] = path
|
ENV['GEM_PATH'] = path
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = "-"
|
|
||||||
|
|
||||||
|
with_rubygems_gemdeps("-") do
|
||||||
Dir.mkdir "sub1"
|
Dir.mkdir "sub1"
|
||||||
|
|
||||||
new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
||||||
|
@ -1829,6 +1827,7 @@ class TestGem < Gem::TestCase
|
||||||
|
|
||||||
assert_equal ["b-1", "c-1"], out - out0
|
assert_equal ["b-1", "c-1"], out - out0
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_register_default_spec
|
def test_register_default_spec
|
||||||
Gem.clear_default_specs
|
Gem.clear_default_specs
|
||||||
|
@ -1891,8 +1890,7 @@ class TestGem < Gem::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_ENV
|
def test_use_gemdeps_ENV
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil
|
with_rubygems_gemdeps(nil) do
|
||||||
|
|
||||||
spec = util_spec 'a', 1
|
spec = util_spec 'a', 1
|
||||||
|
|
||||||
refute spec.activated?
|
refute spec.activated?
|
||||||
|
@ -1904,8 +1902,7 @@ class TestGem < Gem::TestCase
|
||||||
Gem.use_gemdeps
|
Gem.use_gemdeps
|
||||||
|
|
||||||
refute spec.activated?
|
refute spec.activated?
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_argument_missing
|
def test_use_gemdeps_argument_missing
|
||||||
|
@ -1918,22 +1915,18 @@ class TestGem < Gem::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_argument_missing_match_ENV
|
def test_use_gemdeps_argument_missing_match_ENV
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] =
|
with_rubygems_gemdeps('gem.deps.rb') do
|
||||||
ENV['RUBYGEMS_GEMDEPS'], 'gem.deps.rb'
|
|
||||||
|
|
||||||
e = assert_raise ArgumentError do
|
e = assert_raise ArgumentError do
|
||||||
Gem.use_gemdeps 'gem.deps.rb'
|
Gem.use_gemdeps 'gem.deps.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
|
assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
|
||||||
e.message
|
e.message
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_automatic
|
def test_use_gemdeps_automatic
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
|
with_rubygems_gemdeps('-') do
|
||||||
|
|
||||||
spec = util_spec 'a', 1
|
spec = util_spec 'a', 1
|
||||||
install_specs spec
|
install_specs spec
|
||||||
spec = Gem::Specification.find {|s| s == spec }
|
spec = Gem::Specification.find {|s| s == spec }
|
||||||
|
@ -1947,23 +1940,19 @@ class TestGem < Gem::TestCase
|
||||||
Gem.use_gemdeps
|
Gem.use_gemdeps
|
||||||
|
|
||||||
assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
|
assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_automatic_missing
|
def test_use_gemdeps_automatic_missing
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
|
with_rubygems_gemdeps('-') do
|
||||||
|
|
||||||
Gem.use_gemdeps
|
Gem.use_gemdeps
|
||||||
|
|
||||||
assert true # count
|
assert true # count
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_disabled
|
def test_use_gemdeps_disabled
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], ''
|
with_rubygems_gemdeps('') do
|
||||||
|
|
||||||
spec = util_spec 'a', 1
|
spec = util_spec 'a', 1
|
||||||
|
|
||||||
refute spec.activated?
|
refute spec.activated?
|
||||||
|
@ -1975,13 +1964,11 @@ class TestGem < Gem::TestCase
|
||||||
Gem.use_gemdeps
|
Gem.use_gemdeps
|
||||||
|
|
||||||
refute spec.activated?
|
refute spec.activated?
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_missing_gem
|
def test_use_gemdeps_missing_gem
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
|
with_rubygems_gemdeps('x') do
|
||||||
|
|
||||||
File.open 'x', 'w' do |io|
|
File.open 'x', 'w' do |io|
|
||||||
io.write 'gem "a"'
|
io.write 'gem "a"'
|
||||||
end
|
end
|
||||||
|
@ -1999,13 +1986,11 @@ You may need to `gem install -g` to install missing gems
|
||||||
assert_empty actual_stdout
|
assert_empty actual_stdout
|
||||||
assert_equal(expected, actual_stderr)
|
assert_equal(expected, actual_stderr)
|
||||||
end
|
end
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_use_gemdeps_specific
|
def test_use_gemdeps_specific
|
||||||
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
|
with_rubygems_gemdeps('x') do
|
||||||
|
|
||||||
spec = util_spec 'a', 1
|
spec = util_spec 'a', 1
|
||||||
install_specs spec
|
install_specs spec
|
||||||
|
|
||||||
|
@ -2019,8 +2004,7 @@ You may need to `gem install -g` to install missing gems
|
||||||
Gem.use_gemdeps
|
Gem.use_gemdeps
|
||||||
|
|
||||||
assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
|
assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
|
||||||
ensure
|
end
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_operating_system_defaults
|
def test_operating_system_defaults
|
||||||
|
@ -2148,4 +2132,12 @@ You may need to `gem install -g` to install missing gems
|
||||||
ENV['PATH'] = path
|
ENV['PATH'] = path
|
||||||
ENV['RUBYOPT'] = rubyopt
|
ENV['RUBYOPT'] = rubyopt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_rubygems_gemdeps(value)
|
||||||
|
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], value
|
||||||
|
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue