summaryrefslogtreecommitdiff
path: root/spec/bundler/remote_specification_spec.rb
blob: fa3534d8a2bfb33a09e8dbbe2d8982b631849ded (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
require "spec_helper"

describe Bundler::RemoteSpecification do
  it "is Comparable" do
    expect(described_class.ancestors).to include(Comparable)
  end

  describe "#<=>" do
    let(:name) { "foo" }
    let(:version) { Gem::Version.new("1.0.0") }
    let(:platform) { Gem::Platform::RUBY }

    let(:other_name) { name }
    let(:other_version) { version }
    let(:other_platform) { platform }

    subject do
      Bundler::RemoteSpecification.new(name, version, platform, nil)
    end

    shared_examples_for "a comparison" do
      context "which exactly matches" do
        it "returns 0" do
          expect(subject <=> other).to eq(0)
        end
      end

      context "which is different by name" do
        let(:other_name) { "a" }
        it "doesn't return 0" do
          expect(subject <=> other).not_to eq(0)
        end
      end

      context "which has a lower version" do
        let(:other_version) { Gem::Version.new("0.9.0") }
        it "returns 1" do
          expect(subject <=> other).to eq(1)
        end
      end

      context "which has a higher version" do
        let(:other_version) { Gem::Version.new("1.1.0") }
        it "returns -1" do
          expect(subject <=> other).to eq(-1)
        end
      end

      context "which has a different platform" do
        let(:other_platform) { Gem::Platform.new("x86-mswin32") }
        it "doesn't return 0" do
          expect(subject <=> other).not_to eq(0)
        end
      end
    end

    context "comparing another Bundler::RemoteSpecification" do
      let(:other) do
        Bundler::RemoteSpecification.new(other_name, other_version,
                                         other_platform, nil)
      end

      it_should_behave_like "a comparison"
    end

    context "comparing a Gem::Specification" do
      let(:other) do
        Gem::Specification.new(other_name, other_version).tap do |s|
          s.platform = other_platform
        end
      end

      it_should_behave_like "a comparison"
    end
  end
end