2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2011-01-29 02:46:47 +03:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2011-01-29 02:46:47 +03:00
|
|
|
class TestKernel < Gem::TestCase
|
2007-11-10 10:48:56 +03:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@old_path = $:.dup
|
|
|
|
|
|
|
|
util_make_gems
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
|
|
|
|
$:.replace @old_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem
|
2007-12-20 11:39:12 +03:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
|
|
|
assert $:.any? { |p| %r{a-1/lib} =~ p }
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
2014-12-07 03:53:01 +03: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')
|
|
|
|
|
|
|
|
assert_raises Gem::LoadError do
|
|
|
|
gem('a', '= 2')
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a1, Gem.loaded_specs['a']
|
|
|
|
end
|
|
|
|
|
2011-01-29 02:46:47 +03:00
|
|
|
def test_gem_redundant
|
2007-12-20 11:39:12 +03:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
2009-06-10 01:38:59 +04:00
|
|
|
refute gem('a', '= 1'), "Should not load"
|
2007-12-20 11:39:12 +03:00
|
|
|
assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_overlapping
|
2007-12-20 11:39:12 +03:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
2009-06-10 01:38:59 +04:00
|
|
|
refute gem('a', '>= 1'), "Should not load"
|
2007-12-20 11:39:12 +03:00
|
|
|
assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
2014-09-14 07: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-28 05:26:39 +03:00
|
|
|
def test_gem_env_req
|
|
|
|
ENV["GEM_REQUIREMENT_A"] = '~> 2.0'
|
2016-04-06 09:01:14 +03:00
|
|
|
assert_raises(Gem::MissingSpecVersionError) { gem('a', '= 1') }
|
2016-03-28 05:26:39 +03:00
|
|
|
assert gem('a', '> 1')
|
|
|
|
assert_equal @a2, Gem.loaded_specs['a']
|
|
|
|
end
|
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def test_gem_conflicting
|
2007-12-20 11:39:12 +03:00
|
|
|
assert gem('a', '= 1'), "Should load"
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
ex = assert_raises Gem::LoadError do
|
2007-12-20 11:39:12 +03:00
|
|
|
gem 'a', '= 2'
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
assert_equal "can't activate a-2, already activated a-1", ex.message
|
2007-12-20 11:39:12 +03:00
|
|
|
assert_match(/activated a-1/, ex.message)
|
2009-06-10 01:38:59 +04:00
|
|
|
assert_equal 'a', ex.name
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2007-12-20 11:39:12 +03:00
|
|
|
assert $:.any? { |p| %r{a-1/lib} =~ p }
|
2009-06-10 01:38:59 +04:00
|
|
|
refute $:.any? { |p| %r{a-2/lib} =~ p }
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
2011-01-19 03:08:49 +03:00
|
|
|
def test_gem_not_adding_bin
|
|
|
|
assert gem('a', '= 1'), "Should load"
|
|
|
|
refute $:.any? { |p| %r{a-1/bin} =~ p }
|
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|