2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2013-10-18 05:57:00 +04:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
|
2013-11-19 04:34:13 +04:00
|
|
|
class TestGemResolverVendorSet < Gem::TestCase
|
2013-10-18 05:57:00 +04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2013-11-19 04:34:13 +04:00
|
|
|
@set = Gem::Resolver::VendorSet.new
|
2013-10-18 05:57:00 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_vendor_gem
|
|
|
|
name, version, directory = vendor_gem
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
added = @set.add_vendor_gem name, directory
|
2013-10-18 05:57:00 +04:00
|
|
|
|
|
|
|
spec = @set.load_spec name, version, Gem::Platform::RUBY, nil
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
assert_equal spec, added
|
|
|
|
|
2013-10-18 05:57:00 +04:00
|
|
|
assert_equal "#{name}-#{version}", spec.full_name
|
2013-11-25 23:14:49 +04:00
|
|
|
|
|
|
|
assert_equal File.expand_path(directory), spec.full_gem_path
|
2013-10-18 05:57:00 +04:00
|
|
|
end
|
|
|
|
|
2013-10-20 04:31:12 +04:00
|
|
|
def test_add_vendor_gem_missing
|
2013-11-10 21:51:40 +04:00
|
|
|
name, _, directory = vendor_gem
|
2013-10-20 04:31:12 +04:00
|
|
|
|
|
|
|
FileUtils.rm_r directory
|
|
|
|
|
|
|
|
e = assert_raises Gem::GemNotFoundException do
|
|
|
|
@set.add_vendor_gem name, directory
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "unable to find #{directory}/#{name}.gemspec for gem #{name}",
|
|
|
|
e.message
|
|
|
|
end
|
|
|
|
|
2013-10-18 05:57:00 +04:00
|
|
|
def test_find_all
|
|
|
|
name, version, directory = vendor_gem
|
|
|
|
|
|
|
|
@set.add_vendor_gem name, directory
|
|
|
|
|
|
|
|
dependency = dep 'a', '~> 1'
|
|
|
|
|
2013-11-19 04:34:13 +04:00
|
|
|
req = Gem::Resolver::DependencyRequest.new dependency, nil
|
2013-10-18 05:57:00 +04:00
|
|
|
|
|
|
|
found = @set.find_all req
|
|
|
|
|
|
|
|
spec = @set.load_spec name, version, Gem::Platform::RUBY, nil
|
|
|
|
|
2013-11-10 21:51:40 +04:00
|
|
|
source = Gem::Source::Vendor.new directory
|
|
|
|
|
2013-10-18 05:57:00 +04:00
|
|
|
expected = [
|
2013-11-19 04:34:13 +04:00
|
|
|
Gem::Resolver::VendorSpecification.new(@set, spec, source)
|
2013-10-18 05:57:00 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, found
|
|
|
|
end
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
def test_find_all_prerelease
|
|
|
|
name, _, directory = vendor_gem 'a', '1.a'
|
|
|
|
|
|
|
|
@set.add_vendor_gem name, directory
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep('a'), nil
|
|
|
|
|
|
|
|
assert_empty @set.find_all req
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep('a', '>= 0.a'), nil
|
|
|
|
|
|
|
|
refute_empty @set.find_all req
|
|
|
|
end
|
|
|
|
|
2013-10-18 05:57:00 +04:00
|
|
|
def test_load_spec
|
2013-11-10 21:51:40 +04:00
|
|
|
error = Object.const_defined?(:KeyError) ? KeyError : IndexError
|
|
|
|
|
|
|
|
assert_raises error do
|
2013-12-08 23:32:07 +04:00
|
|
|
@set.load_spec 'b', v(1), Gem::Platform::RUBY, nil
|
2013-10-18 05:57:00 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|