File: artifact_spec.rb

package info (click to toggle)
ruby-solve 4.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,708 kB
  • sloc: ruby: 36,626; makefile: 3
file content (137 lines) | stat: -rw-r--r-- 4,051 bytes parent folder | download | duplicates (2)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require "spec_helper"

describe Solve::Artifact do
  let(:graph) do
    package = double("package")
    package_version = double("package_version")
    package_version.stub(:dependencies).and_return([])
    package.stub(:add_version).and_return(package_version)
    double("graph", dep_graph: double("dep_graph", package: package))
  end

  let(:name) { "league" }
  let(:version) { "1.0.0" }
  subject { Solve::Artifact.new(graph, name, version) }

  describe "equality" do
    context "given an artifact with the same name and version" do
      let(:one) { Solve::Artifact.new(graph, "riot", "1.0.0") }
      let(:two) { Solve::Artifact.new(graph, "riot", "1.0.0") }

      it "is equal" do
        expect(one).to eq(two)
      end
    end

    context "given an artifact with the same name but different version" do
      let(:one) { Solve::Artifact.new(graph, "riot", "1.0.0") }
      let(:two) { Solve::Artifact.new(graph, "riot", "2.0.0") }

      it "is not equal" do
        expect(one).to_not eq(two)
      end
    end

    context "given an artifact with the same version but different name" do
      let(:one) { Solve::Artifact.new(graph, "riot", "1.0.0") }
      let(:two) { Solve::Artifact.new(graph, "league", "1.0.0") }

      it "is not equal" do
        expect(one).to_not eq(two)
      end
    end
  end

  describe "sorting" do
    let(:one) { Solve::Artifact.new(graph, "riot", "1.0.0") }
    let(:two) { Solve::Artifact.new(graph, "riot", "2.0.0") }
    let(:three) { Solve::Artifact.new(graph, "riot", "3.0.0") }

    let(:artifacts) do
      [
        one,
        two,
        three,
      ].shuffle
    end

    it "orders artifacts by their version number" do
      sorted = artifacts.sort

      expect(sorted[0]).to eq(one)
      expect(sorted[1]).to eq(two)
      expect(sorted[2]).to eq(three)
    end
  end

  describe "#dependency?" do
    before { subject.depends("nginx", "1.0.0") }

    it "returns false when the dependency does not exist" do
      expect(subject).to have_dependency("nginx", "1.0.0")
    end

    it "returns true when the dependendency exists" do
      expect(subject).to_not have_dependency("apache2", "2.0.0")
    end
  end

  describe "#dependency" do
    before { subject.depends("nginx", "~> 1.2.3") }

    it "returns an instance of Solve::Dependency matching the given name and constraint" do
      dependency = subject.dependency("nginx", "~> 1.2.3")

      expect(dependency).to be_a(Solve::Dependency)
      expect(dependency.name).to eq("nginx")
      expect(dependency.constraint.to_s).to eq("~> 1.2.3")
    end
  end

  describe "#dependencies" do
    it "returns an array" do
      expect(subject.dependencies).to be_a(Array)
    end

    it "returns an empty array if no dependencies have been accessed" do
      expect(subject.dependencies).to be_empty
    end

    it "returns all dependencies" do
      subject.depends("nginx", "1.0.0")
      subject.depends("nginx", "~> 2.0.0")

      expect(subject.dependencies.size).to eq(2)
    end
  end

  describe "#depends" do
    context "given a name and constraint argument" do
      let(:name) { "nginx" }
      let(:constraint) { "~> 1.0.0" }

      context "given the dependency of the given name and constraint does not exist" do
        it "returns a Solve::Artifact" do
          expect(subject.depends(name, constraint)).to be_a(Solve::Artifact)
        end

        it "adds a dependency with the given name and constraint to the list of dependencies" do
          subject.depends(name, constraint)

          expect(subject.dependencies.size).to eq(1)
          expect(subject.dependencies.first.name).to eq(name)
          expect(subject.dependencies.first.constraint.to_s).to eq(constraint)
        end
      end
    end

    context "given only a name argument" do
      it "adds a dependency with a all constraint (>= 0.0.0)" do
        subject.depends("nginx")

        expect(subject.dependencies.size).to eq(1)
        expect(subject.dependencies.first.constraint.to_s).to eq(">= 0.0.0")
      end
    end
  end
end