diff options
Diffstat (limited to 'test/rubygems/test_gem.rb')
-rw-r--r-- | test/rubygems/test_gem.rb | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index aec9d98c9a..aa57261d5e 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -473,6 +473,45 @@ class TestGem < Gem::TestCase assert_equal cwd, $LOAD_PATH.shift end + def test_self_find_files_with_gemfile + # write_file(File.join Dir.pwd, 'Gemfile') fails on travis 1.8.7 with $SAFE=1 + skip if RUBY_VERSION <= "1.8.7" + + cwd = File.expand_path("test/rubygems", @@project_dir) + $LOAD_PATH.unshift cwd + + discover_path = File.join 'lib', 'sff', 'discover.rb' + + foo1, _ = %w(1 2).map { |version| + spec = quick_gem 'sff', version do |s| + s.files << discover_path + end + + write_file(File.join 'gems', spec.full_name, discover_path) do |fp| + fp.puts "# #{spec.full_name}" + end + + spec + } + Gem.refresh + + write_file(File.join Dir.pwd, 'Gemfile') do |fp| + fp.puts "source 'https://rubygems.org'" + fp.puts "gem '#{foo1.name}', '#{foo1.version}'" + end + Gem.use_gemdeps(File.join Dir.pwd, 'Gemfile') + + expected = [ + File.expand_path('test/rubygems/sff/discover.rb', @@project_dir), + File.join(foo1.full_gem_path, discover_path) + ] + + assert_equal expected, Gem.find_files('sff/discover') + assert_equal expected, Gem.find_files('sff/**.rb'), '[ruby-core:31730]' + ensure + assert_equal cwd, $LOAD_PATH.shift unless RUBY_VERSION <= "1.8.7" + end + def test_self_find_latest_files cwd = File.expand_path("test/rubygems", @@project_dir) $LOAD_PATH.unshift cwd @@ -929,6 +968,26 @@ class TestGem < Gem::TestCase assert_match %r%Could not find 'b' %, e.message end + def test_self_try_activate_missing_prerelease + b = util_spec 'b', '1.0rc1' + a = util_spec 'a', '1.0rc1', 'b' => '1.0rc1' + + install_specs b, a + uninstall_gem b + + a_file = File.join a.gem_dir, 'lib', 'a_file.rb' + + write_file a_file do |io| + io.puts '# a_file.rb' + end + + e = assert_raises Gem::LoadError do + Gem.try_activate 'a_file' + end + + assert_match %r%Could not find 'b' \(= 1.0rc1\)%, e.message + end + def test_self_try_activate_missing_extensions spec = util_spec 'ext', '1' do |s| s.extensions = %w[ext/extconf.rb] @@ -951,6 +1010,45 @@ class TestGem < Gem::TestCase assert_equal expected, err end + def test_self_use_paths_with_nils + orig_home = ENV.delete 'GEM_HOME' + orig_path = ENV.delete 'GEM_PATH' + Gem.use_paths nil, nil + assert_equal Gem.default_dir, Gem.paths.home + assert_equal (Gem.default_path + [Gem.paths.home]).uniq, Gem.paths.path + ensure + ENV['GEM_HOME'] = orig_home + ENV['GEM_PATH'] = orig_path + end + + def test_setting_paths_does_not_warn_about_unknown_keys + stdout, stderr = capture_io do + Gem.paths = { 'foo' => [], + 'bar' => Object.new, + 'GEM_HOME' => Gem.paths.home, + 'GEM_PATH' => 'foo' } + end + assert_equal ['foo', Gem.paths.home], Gem.paths.path + assert_equal '', stderr + assert_equal '', stdout + end + + def test_setting_paths_does_not_mutate_parameter_object + Gem.paths = { 'GEM_HOME' => Gem.paths.home, + 'GEM_PATH' => 'foo' }.freeze + assert_equal ['foo', Gem.paths.home], Gem.paths.path + end + + def test_deprecated_paths= + stdout, stderr = capture_io do + Gem.paths = { 'GEM_HOME' => Gem.paths.home, + 'GEM_PATH' => [Gem.paths.home, 'foo'] } + end + assert_equal [Gem.paths.home, 'foo'], Gem.paths.path + assert_match(/Array values in the parameter are deprecated. Please use a String or nil/, stderr) + assert_equal '', stdout + end + def test_self_use_paths util_ensure_gem_dirs |