2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/gem_path_searcher'
|
|
|
|
|
|
|
|
class Gem::GemPathSearcher
|
|
|
|
attr_accessor :gemspecs
|
|
|
|
attr_accessor :lib_dirs
|
|
|
|
end
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemGemPathSearcher < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
@foo1 = new_spec 'foo', '0.1', nil, "lib/foo.rb"
|
|
|
|
@foo1.require_paths << 'lib2'
|
2007-11-10 02:48:56 -05:00
|
|
|
path = File.join 'gems', @foo1.full_name, 'lib', 'foo.rb'
|
|
|
|
write_file(path) { |fp| fp.puts "# #{path}" }
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
@foo2 = new_spec 'foo', '0.2'
|
|
|
|
@bar1 = new_spec 'bar', '0.1'
|
|
|
|
@bar2 = new_spec 'bar', '0.2'
|
|
|
|
@nrp = new_spec 'nil_require_paths', '0.1' do |s|
|
|
|
|
s.require_paths = nil
|
|
|
|
end
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
util_setup_fake_fetcher
|
|
|
|
Gem::Specification.reset
|
|
|
|
util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@fetcher = Gem::FakeFetcher.new
|
|
|
|
Gem::RemoteFetcher.fetcher = @fetcher
|
|
|
|
|
2011-10-03 18:15:47 -04:00
|
|
|
@gps = Gem::Deprecate.skip_during { Gem::GemPathSearcher.new }
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_find
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal @foo1, @gps.find('foo')
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def test_find_all
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal [@foo1], @gps.find_all('foo')
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_init_gemspecs
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
util_clear_gems
|
|
|
|
util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
|
|
|
|
expected = [@bar2, @bar1, @foo2, @foo1].map(&:full_name)
|
|
|
|
actual = @gps.init_gemspecs.map(&:full_name)
|
|
|
|
assert_equal expected, actual
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_lib_dirs_for
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
lib_dirs = @gps.lib_dirs_for(@foo1)
|
|
|
|
expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal expected, lib_dirs
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_lib_dirs_for_nil_require_paths
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_nil @gps.lib_dirs_for(@nrp)
|
|
|
|
end
|
2010-02-21 21:52:35 -05:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def test_matching_file_eh
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
refute @gps.matching_file?(@foo1, 'bar')
|
|
|
|
assert @gps.matching_file?(@foo1, 'foo')
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_matching_files
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal [], @gps.matching_files(@foo1, 'bar')
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal [expected], @gps.matching_files(@foo1, 'foo')
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_matching_files_nil_require_paths
|
2011-10-03 18:15:47 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_empty @gps.matching_files(@nrp, 'foo')
|
|
|
|
end
|
2010-02-21 21:52:35 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|