summaryrefslogtreecommitdiff
path: root/spec/resolver/engine_spec.rb
blob: e7d0f1953ed9f739ba599e4806c45d935afce144 (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
113
114
115
116
117
118
119
120
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "Resolving specs" do
  it "supports a single dependency" do
    index = build_index do
      add_spec "bar", "2.0.0"
    end

    deps = [
      build_dep("bar", ">= 1.2.3"),
    ]

    solution = Bundler::Resolver.resolve(deps, index)
    solution.should match_gems(
      "bar" => ["2.0.0"]
    )
  end

  it "supports a crazy case" do
    index = build_index do
      add_spec "activemerchant", "1.4.1" do
        runtime "activesupport", ">= 1.4.1"
      end
      add_spec "activesupport", "3.0.0"
      add_spec "activesupport", "2.3.2"
      add_spec "action_pack", "2.3.2" do
        runtime "activesupport", "= 2.3.2"
      end
    end

    deps = [
      build_dep("activemerchant", ">= 0"),
      build_dep("action_pack", "= 2.3.2")
    ]

    solution = Bundler::Resolver.resolve(deps, index)
    solution.should match_gems(
      "activemerchant" => ["1.4.1"],
      "action_pack" => ["2.3.2"],
      "activesupport" => ["2.3.2"]
    )
  end

  it "supports nested dependencies" do
    index = build_index do
      add_spec "bar", "2.0.0" do
        runtime "foo", ">= 1"
      end
      add_spec "foo", "1.1"
    end

    deps = [
      build_dep("bar", ">= 1.2.3"),
    ]

    solution = Bundler::Resolver.resolve(deps, index)
    solution.should match_gems(
      "bar" => ["2.0.0"],
      "foo" => ["1.1"]
    )
  end

  it "supports locked dependencies" do
    index = build_index do
      add_spec "bar", "1.0" do
        runtime "foo", "= 1.0"
      end
      add_spec "bar", "1.1" do
        runtime "foo", "= 1.1"
      end
      add_spec "foo", "1.0"
      add_spec "foo", "1.1"
    end

    deps = [
      build_dep("bar", ">= 1.0"),
      build_dep("foo", "= 1.0"),
    ]

    solution = Bundler::Resolver.resolve(deps, index)
    solution.should match_gems(
      "bar" => ["1.0"],
      "foo" => ["1.0"]
    )
  end

  it "supports merb-core" do
    index = Gem::SourceIndex.from_gems_in(gem_repo3.join("specifications"))

    deps = [
      build_dep("merb-core", "= 1.0.7.1"),
    ]

    solution = Bundler::Resolver.resolve(deps, index)
    solution.should match_gems(
      "merb-core"=>["1.0.7.1"],
      "rake"=>["0.8.7"],
      "thor"=>["0.9.9"],
      "rspec"=>["1.2.2"],
      "mime-types"=>["1.16"],
      "abstract"=>["1.0.0"],
      "rack"=>["1.0.0"],
      "erubis"=>["2.6.4"],
      "extlib"=>["0.9.12"],
      "json_pure"=>["1.1.7"]
    )
  end

  it "supports impossible situations" do
    index = build_index do
      add_spec "a", "1.0"
    end

    deps = [
      build_dep("a", "= 1.1"),
    ]

    Bundler::Resolver.resolve(deps, index).should be_nil
  end
end