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
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestKernel < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@old_path = $:.dup
|
|
|
|
|
|
|
|
util_make_gems
|
2021-05-28 06:47:49 -04:00
|
|
|
|
|
|
|
without_any_upwards_gemfiles
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
|
|
|
|
$:.replace @old_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem
|
2007-12-20 03:39:12 -05:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
2020-06-10 13:46:05 -04:00
|
|
|
assert $:.any? {|p| %r{a-1/lib} =~ p }
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2014-12-06 19:53:01 -05:00
|
|
|
def test_gem_default
|
|
|
|
assert gem('a', '>= 0')
|
|
|
|
|
|
|
|
assert_equal @a2, Gem.loaded_specs['a']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_default_re_gem
|
|
|
|
assert gem('a', '=1')
|
|
|
|
|
|
|
|
refute gem('a', '>= 0')
|
|
|
|
|
|
|
|
assert_equal @a1, Gem.loaded_specs['a']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_re_gem_mismatch
|
|
|
|
assert gem('a', '=1')
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::LoadError do
|
2014-12-06 19:53:01 -05:00
|
|
|
gem('a', '= 2')
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a1, Gem.loaded_specs['a']
|
|
|
|
end
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
def test_gem_redundant
|
2007-12-20 03:39:12 -05:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
2009-06-09 17:38:59 -04:00
|
|
|
refute gem('a', '= 1'), "Should not load"
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal 1, $:.select {|p| %r{a-1/lib} =~ p }.size
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_overlapping
|
2007-12-20 03:39:12 -05:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
2009-06-09 17:38:59 -04:00
|
|
|
refute gem('a', '>= 1'), "Should not load"
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal 1, $:.select {|p| %r{a-1/lib} =~ p }.size
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_gem_prerelease
|
|
|
|
quick_gem 'd', '1.1.a'
|
|
|
|
refute gem('d', '>= 1'), 'release requirement must not load prerelease'
|
|
|
|
assert gem('d', '>= 1.a'), 'prerelease requirement may load prerelease'
|
|
|
|
end
|
|
|
|
|
2016-03-27 22:26:39 -04:00
|
|
|
def test_gem_env_req
|
|
|
|
ENV["GEM_REQUIREMENT_A"] = '~> 2.0'
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise(Gem::MissingSpecVersionError) { gem('a', '= 1') }
|
2016-03-27 22:26:39 -04:00
|
|
|
assert gem('a', '> 1')
|
|
|
|
assert_equal @a2, Gem.loaded_specs['a']
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_gem_conflicting
|
2007-12-20 03:39:12 -05:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
ex = assert_raise Gem::LoadError do
|
2007-12-20 03:39:12 -05:00
|
|
|
gem 'a', '= 2'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal "can't activate a-2, already activated a-1", ex.message
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_match(/activated a-1/, ex.message)
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_equal 'a', ex.name
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
assert $:.any? {|p| %r{a-1/lib} =~ p }
|
|
|
|
refute $:.any? {|p| %r{a-2/lib} =~ p }
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
def test_gem_not_adding_bin
|
|
|
|
assert gem('a', '= 1'), "Should load"
|
2020-06-10 13:46:05 -04:00
|
|
|
refute $:.any? {|p| %r{a-1/bin} =~ p }
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
2017-10-07 21:32:18 -04:00
|
|
|
|
2020-03-27 13:31:51 -04:00
|
|
|
def test_gem_failing_inside_require_doesnt_cause_double_exceptions
|
|
|
|
File.write("activate.rb", "gem('a', '= 999')\n")
|
|
|
|
|
|
|
|
require "open3"
|
|
|
|
|
|
|
|
output, _ = Open3.capture2e(
|
|
|
|
{ "GEM_HOME" => Gem.paths.home },
|
2020-04-08 15:14:27 -04:00
|
|
|
*ruby_with_rubygems_in_load_path,
|
2020-03-27 13:31:51 -04:00
|
|
|
"-r",
|
|
|
|
"./activate.rb"
|
|
|
|
)
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
load_errors = output.split("\n").select {|line| line.include?("Could not find") }
|
2020-03-27 13:31:51 -04:00
|
|
|
|
|
|
|
assert_equal 1, load_errors.size
|
|
|
|
end
|
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
def test_gem_bundler
|
|
|
|
quick_gem 'bundler', '1'
|
|
|
|
quick_gem 'bundler', '2.a'
|
|
|
|
|
|
|
|
assert gem('bundler')
|
2020-06-10 13:46:05 -04:00
|
|
|
assert $:.any? {|p| %r{bundler-1/lib} =~ p }
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_bundler_missing_bundler_version
|
|
|
|
Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["55", "reason"]) do
|
|
|
|
quick_gem 'bundler', '1'
|
|
|
|
quick_gem 'bundler', '2.a'
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::MissingSpecVersionError do
|
2017-10-07 21:32:18 -04:00
|
|
|
gem('bundler')
|
|
|
|
end
|
|
|
|
assert_match "Could not find 'bundler' (55) required by reason.", e.message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_bundler_inferred_bundler_version
|
|
|
|
Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["1", "reason"]) do
|
|
|
|
quick_gem 'bundler', '1'
|
|
|
|
quick_gem 'bundler', '2.a'
|
|
|
|
|
|
|
|
assert gem('bundler', '>= 0.a')
|
2020-06-10 13:46:05 -04:00
|
|
|
assert $:.any? {|p| %r{bundler-1/lib} =~ p }
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|