2011-05-31 23:45:05 -04:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
class TestGemPathSupport < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
ENV["GEM_HOME"] = @tempdir
|
|
|
|
ENV["GEM_PATH"] = [@tempdir, "something"].join(File::PATH_SEPARATOR)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
|
|
|
ps = Gem::PathSupport.new
|
|
|
|
|
|
|
|
assert_equal ENV["GEM_HOME"], ps.home
|
|
|
|
|
|
|
|
expected = util_path
|
|
|
|
assert_equal expected, ps.path, "defaults to GEM_PATH"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_home
|
|
|
|
ps = Gem::PathSupport.new "GEM_HOME" => "#{@tempdir}/foo"
|
|
|
|
|
2011-08-25 21:10:50 -04:00
|
|
|
expected = File.join(@tempdir, "foo")
|
|
|
|
assert_equal expected, ps.home
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2011-08-25 21:10:50 -04:00
|
|
|
assert_equal [expected, *util_path], ps.path
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2011-07-26 21:40:07 -04:00
|
|
|
if defined?(File::ALT_SEPARATOR) and File::ALT_SEPARATOR
|
|
|
|
def test_initialize_home_normalize
|
|
|
|
alternate = @tempdir.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
|
|
|
|
ps = Gem::PathSupport.new "GEM_HOME" => alternate
|
|
|
|
|
|
|
|
assert_equal @tempdir, ps.home, "normalize values"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_initialize_path
|
|
|
|
ps = Gem::PathSupport.new "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar]
|
|
|
|
|
|
|
|
assert_equal ENV["GEM_HOME"], ps.home
|
|
|
|
|
|
|
|
expected = [
|
2011-08-25 21:10:50 -04:00
|
|
|
ENV["GEM_HOME"],
|
2011-05-31 23:45:05 -04:00
|
|
|
File.join(@tempdir, 'foo'),
|
|
|
|
File.join(@tempdir, 'bar'),
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, ps.path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_home_path
|
|
|
|
ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
|
|
|
|
"GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar])
|
|
|
|
|
|
|
|
assert_equal File.join(@tempdir, "foo"), ps.home
|
|
|
|
|
|
|
|
expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')]
|
|
|
|
assert_equal expected, ps.path
|
|
|
|
end
|
|
|
|
|
2011-08-25 21:10:50 -04:00
|
|
|
def test_path_equals
|
|
|
|
ps = Gem::PathSupport.new
|
|
|
|
|
|
|
|
ps.send :path=, ['a', 'b']
|
|
|
|
|
|
|
|
assert_equal [@tempdir, 'a', 'b'], ps.path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_path_equals_empty
|
|
|
|
ps = Gem::PathSupport.new
|
|
|
|
|
|
|
|
ps.send :path=, nil
|
|
|
|
|
|
|
|
assert_equal [@tempdir, 'something'], ps.path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_path_equals_empty_no_GEM_PATH
|
|
|
|
ENV.delete 'GEM_PATH'
|
|
|
|
|
|
|
|
ps = Gem::PathSupport.new
|
|
|
|
|
|
|
|
ps.send :path=, nil
|
|
|
|
|
|
|
|
assert_equal [@tempdir, *Gem.default_path], ps.path
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def util_path
|
|
|
|
ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
|
|
|
|
end
|
|
|
|
end
|