summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_resolver_lock_specification.rb
blob: 5741950fe0de16ab693e088c96f4acba9aca379b (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'rubygems/test_case'
require 'rubygems/resolver'

class TestGemResolverLockSpecification < Gem::TestCase

  def setup
    super

    @LS = Gem::Resolver::LockSpecification

    @source = Gem::Source.new @gem_repo
    @set    = Gem::Resolver::LockSet.new @source
  end

  def test_initialize
    spec = @LS.new @set, 'a', v(2), @source, Gem::Platform::RUBY

    assert_equal 'a',                 spec.name
    assert_equal v(2),                spec.version
    assert_equal Gem::Platform::RUBY, spec.platform

    assert_equal @source, spec.source
  end

  def test_add_dependency
    l_spec = @LS.new @set, 'a', v(2), @source, Gem::Platform::RUBY

    b_dep = dep('b', '>= 0')

    l_spec.add_dependency b_dep

    assert_equal [b_dep], l_spec.dependencies
  end

  def test_install
    spec_fetcher do |fetcher|
      fetcher.gem 'a', 2
      fetcher.clear
    end

    spec = @LS.new @set, 'a', v(2), @source, Gem::Platform::RUBY

    called = false

    spec.install({}) do |installer|
      called = installer
    end

    refute_nil called
  end

  def test_install_installed
    spec = @LS.new @set, 'a', v(2), @source, Gem::Platform::RUBY

    FileUtils.touch File.join(@gemhome, 'specifications', spec.spec.spec_name)

    called = false

    spec.install({}) do |installer|
      called = installer
    end

    assert_nil called
  end

  def test_spec
    version = v(2)

    l_spec = @LS.new @set, 'a', version, @source, Gem::Platform::RUBY

    b_dep = dep 'b', '>= 0'
    c_dep = dep 'c', '~> 1'

    l_spec.add_dependency b_dep
    l_spec.add_dependency c_dep

    spec = l_spec.spec

    assert_equal 'a',                 spec.name
    assert_equal version,             spec.version
    assert_equal Gem::Platform::RUBY, spec.platform

    assert_equal [b_dep, c_dep], l_spec.spec.dependencies
  end

end