summaryrefslogtreecommitdiff
path: root/test/rubygems/test_kernel.rb
blob: da31d772eb7886eae0318fe8ede672e8ed8f518f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/package'

class TestKernel < RubyGemTestCase

  def setup
    super

    @old_path = $:.dup

    util_make_gems
  end

  def teardown
    super

    $:.replace @old_path
  end

  def test_gem
    assert gem('a', '= 1'), "Should load"
    assert $:.any? { |p| %r{a-1/lib} =~ p }
    assert $:.any? { |p| %r{a-1/bin} =~ p }
  end

  def test_gem_redundent
    assert gem('a', '= 1'), "Should load"
    assert ! gem('a', '= 1'), "Should not load"
    assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
    assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size
  end

  def test_gem_overlapping
    assert gem('a', '= 1'), "Should load"
    assert ! gem('a', '>= 1'), "Should not load"
    assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
    assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size
  end

  def test_gem_conflicting
    assert gem('a', '= 1'), "Should load"

    ex = assert_raise Gem::Exception do
      gem 'a', '= 2'
    end

    assert_match(/activate a \(= 2, runtime\)/, ex.message)
    assert_match(/activated a-1/, ex.message)

    assert $:.any? { |p| %r{a-1/lib} =~ p }
    assert $:.any? { |p| %r{a-1/bin} =~ p }
    assert ! $:.any? { |p| %r{a-2/lib} =~ p }
    assert ! $:.any? { |p| %r{a-2/bin} =~ p }
  end

end