summaryrefslogtreecommitdiff
path: root/spec/bundler/bundler/source/git_spec.rb
blob: feef54bbf424f43596e9aa13d6e4c27c4fb8e41d (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
# frozen_string_literal: true

RSpec.describe Bundler::Source::Git do
  before do
    allow(Bundler).to receive(:root) { Pathname.new("root") }
  end

  let(:uri) { "https://github.com/foo/bar.git" }
  let(:options) do
    { "uri" => uri }
  end

  subject { described_class.new(options) }

  describe "#to_s" do
    it "returns a description" do
      expect(subject.to_s).to eq "https://github.com/foo/bar.git"
    end

    context "when the URI contains credentials" do
      let(:uri) { "https://my-secret-token:x-oauth-basic@github.com/foo/bar.git" }

      it "filters credentials" do
        expect(subject.to_s).to eq "https://x-oauth-basic@github.com/foo/bar.git"
      end
    end

    context "when the source has a glob specifier" do
      let(:glob) { "bar/baz/*.gemspec" }
      let(:options) do
        { "uri" => uri, "glob" => glob }
      end

      it "includes it" do
        expect(subject.to_s).to eq "https://github.com/foo/bar.git (glob: bar/baz/*.gemspec)"
      end
    end

    context "when the source has a reference" do
      let(:git_proxy_stub) do
        instance_double(Bundler::Source::Git::GitProxy, revision: "123abc", branch: "v1.0.0")
      end
      let(:options) do
        { "uri" => uri, "ref" => "v1.0.0" }
      end

      before do
        allow(Bundler::Source::Git::GitProxy).to receive(:new).and_return(git_proxy_stub)
      end

      it "includes it" do
        expect(subject.to_s).to eq "https://github.com/foo/bar.git (at v1.0.0@123abc)"
      end
    end

    context "when the source has both reference and glob specifiers" do
      let(:git_proxy_stub) do
        instance_double(Bundler::Source::Git::GitProxy, revision: "123abc", branch: "v1.0.0")
      end
      let(:options) do
        { "uri" => uri, "ref" => "v1.0.0", "glob" => "gems/foo/*.gemspec" }
      end

      before do
        allow(Bundler::Source::Git::GitProxy).to receive(:new).and_return(git_proxy_stub)
      end

      it "includes both" do
        expect(subject.to_s).to eq "https://github.com/foo/bar.git (at v1.0.0@123abc, glob: gems/foo/*.gemspec)"
      end
    end
  end
end