summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rubygems/test_gem_resolver_git_specification.rb
blob: a31674a21899a4314f432e7c98ef876f3f168e7b (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require 'rubygems/test_case'

class TestGemResolverGitSpecification < Gem::TestCase

  def setup
    super

    @set  = Gem::Resolver::GitSet.new
    @spec = Gem::Specification.new 'a', 1
  end

  def test_equals2
    g_spec_a = Gem::Resolver::GitSpecification.new @set, @spec

    assert_equal g_spec_a, g_spec_a

    spec_b = Gem::Specification.new 'b', 1
    g_spec_b = Gem::Resolver::GitSpecification.new @set, spec_b

    refute_equal g_spec_a, g_spec_b

    g_set = Gem::Resolver::GitSet.new
    g_spec_s = Gem::Resolver::GitSpecification.new g_set, @spec

    refute_equal g_spec_a, g_spec_s

    i_set  = Gem::Resolver::IndexSet.new
    source = Gem::Source.new @gem_repo
    i_spec = Gem::Resolver::IndexSpecification.new(
      i_set, 'a', v(1), source, Gem::Platform::RUBY)

    refute_equal g_spec_a, i_spec
  end

  def test_add_dependency
    git_gem 'a', 1

    git_spec = Gem::Resolver::GitSpecification.new @set, @spec

    b_dep = dep 'b'

    git_spec.add_dependency b_dep

    assert_equal [b_dep], git_spec.dependencies
  end

  def test_install
    git_gem 'a', 1

    git_spec = Gem::Resolver::GitSpecification.new @set, @spec

    called = false

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

    assert called
  end

  # functional test for Gem::Ext::Builder

  def test_install_extension
    name, _, repository, = git_gem 'a', 1 do |s|
      s.extensions << 'ext/extconf.rb'
    end

    Dir.chdir 'git/a' do
      FileUtils.mkdir_p 'ext/lib'

      open 'ext/extconf.rb', 'w' do |io|
        io.puts 'require "mkmf"'
        io.puts 'create_makefile "a"'
      end

      FileUtils.touch 'ext/lib/b.rb'

      system @git, 'add', 'ext/extconf.rb'
      system @git, 'add', 'ext/lib/b.rb'

      system @git, 'commit', '--quiet', '-m', 'Add extension files'
    end

    source = Gem::Source::Git.new name, repository, 'master', true

    spec = source.specs.first

    git_spec = Gem::Resolver::GitSpecification.new @set, spec, source

    git_spec.install({})

    assert_path_exists File.join git_spec.spec.extension_dir, 'b.rb'
  end

  def test_install_installed
    git_gem 'a', 1

    git_spec = Gem::Resolver::GitSpecification.new @set, @spec

    git_spec.install({})

    called = false

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

    assert called
  end

end