summaryrefslogtreecommitdiff
path: root/spec/bundler/bundler/plugin/installer_spec.rb
blob: e89720f6f73214121104e52726e5db5e0f4084ca (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
121
122
123
124
125
126
127
128
129
130
131
# frozen_string_literal: true

RSpec.describe Bundler::Plugin::Installer do
  subject(:installer) { Bundler::Plugin::Installer.new }

  describe "cli install" do
    it "uses Gem.sources when non of the source is provided" do
      sources = double(:sources)
      Bundler.settings # initialize it before we have to touch rubygems.ext_lock
      allow(Bundler).to receive_message_chain("rubygems.sources") { sources }

      allow(installer).to receive(:install_rubygems).
        with("new-plugin", [">= 0"], sources).once

      installer.install("new-plugin", {})
    end

    describe "with mocked installers" do
      let(:spec) { double(:spec) }
      it "returns the installed spec after installing git plugins" do
        allow(installer).to receive(:install_git).
          and_return("new-plugin" => spec)

        expect(installer.install(["new-plugin"], :git => "https://some.ran/dom")).
          to eq("new-plugin" => spec)
      end

      it "returns the installed spec after installing local git plugins" do
        allow(installer).to receive(:install_local_git).
          and_return("new-plugin" => spec)

        expect(installer.install(["new-plugin"], :local_git => "/phony/path/repo")).
          to eq("new-plugin" => spec)
      end

      it "returns the installed spec after installing rubygems plugins" do
        allow(installer).to receive(:install_rubygems).
          and_return("new-plugin" => spec)

        expect(installer.install(["new-plugin"], :source => "https://some.ran/dom")).
          to eq("new-plugin" => spec)
      end
    end

    describe "with actual installers" do
      before do
        build_repo2 do
          build_plugin "re-plugin"
          build_plugin "ma-plugin"
        end
      end

      context "git plugins" do
        before do
          build_git "ga-plugin", :path => lib_path("ga-plugin") do |s|
            s.write "plugins.rb"
          end
        end

        let(:result) do
          installer.install(["ga-plugin"], :git => file_uri_for(lib_path("ga-plugin")))
        end

        it "returns the installed spec after installing" do
          spec = result["ga-plugin"]
          expect(spec.full_name).to eq "ga-plugin-1.0"
        end

        it "has expected full_gem_path" do
          rev = revision_for(lib_path("ga-plugin"))
          expect(result["ga-plugin"].full_gem_path).
            to eq(Bundler::Plugin.root.join("bundler", "gems", "ga-plugin-#{rev[0..11]}").to_s)
        end
      end

      context "local git plugins" do
        before do
          build_git "ga-plugin", :path => lib_path("ga-plugin") do |s|
            s.write "plugins.rb"
          end
        end

        let(:result) do
          installer.install(["ga-plugin"], :local_git => lib_path("ga-plugin").to_s)
        end

        it "returns the installed spec after installing" do
          spec = result["ga-plugin"]
          expect(spec.full_name).to eq "ga-plugin-1.0"
        end

        it "has expected full_gem_path" do
          rev = revision_for(lib_path("ga-plugin"))
          expect(result["ga-plugin"].full_gem_path).
            to eq(Bundler::Plugin.root.join("bundler", "gems", "ga-plugin-#{rev[0..11]}").to_s)
        end
      end

      context "rubygems plugins" do
        let(:result) do
          installer.install(["re-plugin"], :source => file_uri_for(gem_repo2))
        end

        it "returns the installed spec after installing " do
          expect(result["re-plugin"]).to be_kind_of(Bundler::RemoteSpecification)
        end

        it "has expected full_gem_path" do
          expect(result["re-plugin"].full_gem_path).
            to eq(global_plugin_gem("re-plugin-1.0").to_s)
        end
      end

      context "multiple plugins" do
        let(:result) do
          installer.install(["re-plugin", "ma-plugin"], :source => file_uri_for(gem_repo2))
        end

        it "returns the installed spec after installing " do
          expect(result["re-plugin"]).to be_kind_of(Bundler::RemoteSpecification)
          expect(result["ma-plugin"]).to be_kind_of(Bundler::RemoteSpecification)
        end

        it "has expected full_gem_path" do
          expect(result["re-plugin"].full_gem_path).to eq(global_plugin_gem("re-plugin-1.0").to_s)
          expect(result["ma-plugin"].full_gem_path).to eq(global_plugin_gem("ma-plugin-1.0").to_s)
        end
      end
    end
  end
end