2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2021-06-02 06:32:47 +03:00
|
|
|
require_relative "helper"
|
2013-10-16 10:00:39 +04:00
|
|
|
require "rubygems/source"
|
2012-11-29 10:52:18 +04:00
|
|
|
|
|
|
|
class TestGemSourceSpecificFile < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@a, @a_gem = util_gem "a", "1"
|
|
|
|
@sf = Gem::Source::SpecificFile.new(@a_gem)
|
|
|
|
end
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
def test_path
|
|
|
|
assert_equal @a_gem, @sf.path
|
|
|
|
end
|
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
def test_spec
|
|
|
|
assert_equal @a, @sf.spec
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_load_specs
|
|
|
|
assert_equal [@a.name_tuple], @sf.load_specs
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch_spec
|
|
|
|
assert_equal @a, @sf.fetch_spec(@a.name_tuple)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch_spec_fails_on_unknown_name
|
2021-05-11 06:25:46 +03:00
|
|
|
assert_raise Gem::Exception do
|
2012-11-29 10:52:18 +04:00
|
|
|
@sf.fetch_spec(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_download
|
|
|
|
assert_equal @a_gem, @sf.download(@a)
|
|
|
|
end
|
2013-09-14 12:59:02 +04:00
|
|
|
|
|
|
|
def test_spaceship
|
|
|
|
a1 = quick_gem "a", "1"
|
|
|
|
util_build_gem a1
|
|
|
|
|
|
|
|
remote = Gem::Source.new @gem_repo
|
|
|
|
specific = Gem::Source::SpecificFile.new a1.cache_file
|
|
|
|
installed = Gem::Source::Installed.new
|
|
|
|
local = Gem::Source::Local.new
|
|
|
|
|
2019-05-03 20:56:58 +03:00
|
|
|
assert_equal(0, specific.<=>(specific), "specific <=> specific")
|
2013-09-14 12:59:02 +04:00
|
|
|
|
2019-05-03 20:56:58 +03:00
|
|
|
assert_equal(-1, remote.<=>(specific), "remote <=> specific")
|
|
|
|
assert_equal(1, specific.<=>(remote), "specific <=> remote")
|
2013-09-14 12:59:02 +04:00
|
|
|
|
2020-03-27 15:49:55 +03:00
|
|
|
assert_equal(-1, specific.<=>(local), "specific <=> local")
|
|
|
|
assert_equal(1, local. <=>(specific), "local <=> specific")
|
2013-09-14 12:59:02 +04:00
|
|
|
|
2020-03-27 15:49:55 +03:00
|
|
|
assert_equal(-1, specific. <=>(installed), "specific <=> installed")
|
2019-05-03 20:56:58 +03:00
|
|
|
assert_equal(1, installed.<=>(specific), "installed <=> specific")
|
2013-09-14 12:59:02 +04:00
|
|
|
|
|
|
|
a2 = quick_gem "a", "2"
|
|
|
|
util_build_gem a2
|
|
|
|
|
|
|
|
b1 = quick_gem "b", "1"
|
|
|
|
util_build_gem b1
|
|
|
|
|
|
|
|
a1_source = specific
|
|
|
|
a2_source = Gem::Source::SpecificFile.new a2.cache_file
|
|
|
|
b1_source = Gem::Source::SpecificFile.new b1.cache_file
|
|
|
|
|
|
|
|
assert_nil a1_source.<=>(b1_source), "a1_source <=> b1_source"
|
|
|
|
|
|
|
|
assert_equal(-1, a1_source.<=>(a2_source), "a1_source <=> a2_source")
|
2019-02-14 15:59:03 +03:00
|
|
|
assert_equal(0, a1_source.<=>(a1_source), "a1_source <=> a1_source")
|
|
|
|
assert_equal(1, a2_source.<=>(a1_source), "a2_source <=> a1_source")
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|