~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_path_support.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'rubygems/test_case'
 
2
require 'rubygems'
 
3
require 'fileutils'
 
4
 
 
5
class TestGemPathSupport < Gem::TestCase
 
6
  def setup
 
7
    super
 
8
 
 
9
    ENV["GEM_HOME"] = @tempdir
 
10
    ENV["GEM_PATH"] = [@tempdir, "something"].join(File::PATH_SEPARATOR)
 
11
  end
 
12
 
 
13
  def test_initialize
 
14
    ps = Gem::PathSupport.new
 
15
 
 
16
    assert_equal ENV["GEM_HOME"], ps.home
 
17
 
 
18
    expected = util_path
 
19
    assert_equal expected, ps.path, "defaults to GEM_PATH"
 
20
  end
 
21
 
 
22
  def test_initialize_home
 
23
    ps = Gem::PathSupport.new "GEM_HOME" => "#{@tempdir}/foo"
 
24
 
 
25
    expected = File.join(@tempdir, "foo")
 
26
    assert_equal expected, ps.home
 
27
 
 
28
    assert_equal [expected, *util_path], ps.path
 
29
  end
 
30
 
 
31
  if defined?(File::ALT_SEPARATOR) and File::ALT_SEPARATOR
 
32
    def test_initialize_home_normalize
 
33
      alternate = @tempdir.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
 
34
      ps = Gem::PathSupport.new "GEM_HOME" => alternate
 
35
 
 
36
      assert_equal @tempdir, ps.home, "normalize values"
 
37
    end
 
38
  end
 
39
 
 
40
  def test_initialize_path
 
41
    ps = Gem::PathSupport.new "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar]
 
42
 
 
43
    assert_equal ENV["GEM_HOME"], ps.home
 
44
 
 
45
    expected = [
 
46
                ENV["GEM_HOME"],
 
47
                File.join(@tempdir, 'foo'),
 
48
                File.join(@tempdir, 'bar'),
 
49
               ]
 
50
 
 
51
    assert_equal expected, ps.path
 
52
  end
 
53
 
 
54
  def test_initialize_home_path
 
55
    ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
 
56
                              "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar])
 
57
 
 
58
    assert_equal File.join(@tempdir, "foo"), ps.home
 
59
 
 
60
    expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')]
 
61
    assert_equal expected, ps.path
 
62
  end
 
63
 
 
64
  def test_path_equals
 
65
    ps = Gem::PathSupport.new
 
66
 
 
67
    ps.send :path=, ['a', 'b']
 
68
 
 
69
    assert_equal [@tempdir, 'a', 'b'], ps.path
 
70
  end
 
71
 
 
72
  def test_path_equals_empty
 
73
    ps = Gem::PathSupport.new
 
74
 
 
75
    ps.send :path=, nil
 
76
 
 
77
    assert_equal [@tempdir, 'something'], ps.path
 
78
  end
 
79
 
 
80
  def test_path_equals_empty_no_GEM_PATH
 
81
    ENV.delete 'GEM_PATH'
 
82
 
 
83
    ps = Gem::PathSupport.new
 
84
 
 
85
    ps.send :path=, nil
 
86
 
 
87
    assert_equal [@tempdir, *Gem.default_path], ps.path
 
88
  end
 
89
 
 
90
  def util_path
 
91
    ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
 
92
  end
 
93
end