summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_resolver_index_specification.rb
blob: b479757bd557fe03b12783569ee5b3dbaf3e6233 (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
# frozen_string_literal: true
require_relative "helper"
require "rubygems/available_set"

class TestGemResolverIndexSpecification < Gem::TestCase
  def test_initialize
    set     = Gem::Resolver::IndexSet.new
    source  = Gem::Source.new @gem_repo
    version = Gem::Version.new "3.0.3"

    spec = Gem::Resolver::IndexSpecification.new(
      set, "rails", version, source, Gem::Platform::RUBY)

    assert_equal "rails",             spec.name
    assert_equal version,             spec.version
    assert_equal Gem::Platform::RUBY, spec.platform

    assert_equal source, spec.source
  end

  def test_initialize_platform
    set     = Gem::Resolver::IndexSet.new
    source  = Gem::Source::Local.new
    version = Gem::Version.new "3.0.3"

    spec = Gem::Resolver::IndexSpecification.new(
      set, "rails", version, source, Gem::Platform.local)

    assert_equal Gem::Platform.local, spec.platform
  end

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

    set    = Gem::Resolver::IndexSet.new
    source = Gem::Source.new @gem_repo

    spec = Gem::Resolver::IndexSpecification.new(
      set, "a", v(2), source, Gem::Platform::RUBY)

    called = false

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

    assert_path_exist File.join @gemhome, "specifications", "a-2.gemspec"

    assert_kind_of Gem::Installer, called
  end

  def test_spec
    specs = spec_fetcher do |fetcher|
      fetcher.spec "a", 2
      fetcher.spec "a", 2 do |s|
        s.platform = Gem::Platform.local
      end
    end

    source = Gem::Source.new @gem_repo
    version = v 2

    set = Gem::Resolver::IndexSet.new
    i_spec = Gem::Resolver::IndexSpecification.new \
      set, "a", version, source, Gem::Platform.local

    spec = i_spec.spec

    assert_equal specs["a-2-#{Gem::Platform.local}"].full_name, spec.full_name
  end

  def test_spec_local
    a_2_p = util_spec "a", 2 do |s|
      s.platform = Gem::Platform.local
    end

    Gem::Package.build a_2_p

    source = Gem::Source::Local.new
    set = Gem::Resolver::InstallerSet.new :local
    set.always_install << a_2_p

    i_spec = Gem::Resolver::IndexSpecification.new \
      set, "a", v(2), source, Gem::Platform.local

    spec = i_spec.spec

    assert_equal a_2_p.full_name, spec.full_name
  end
end