File: install_gem_test.rb

package info (click to toggle)
vagrant 2.3.7%2Bgit20230731.5fc64cde%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,616 kB
  • sloc: ruby: 111,820; sh: 462; makefile: 123; ansic: 34; lisp: 1
file content (95 lines) | stat: -rw-r--r-- 2,757 bytes parent folder | download | duplicates (5)
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
require File.expand_path("../../../../../base", __FILE__)

describe VagrantPlugins::CommandPlugin::Action::InstallGem do
  let(:app) { lambda { |env| } }
  let(:env) {{
    ui: Vagrant::UI::Silent.new
  }}

  let(:manager) { double("manager") }

  subject { described_class.new(app, env) }

  before do
    allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager)
  end

  describe "#call" do
    it "should install the plugin" do
      spec = Gem::Specification.new
      expect(manager).to receive(:install_plugin).with(
        "foo", version: nil, require: nil, sources: nil, verbose: false, env_local: nil).once.and_return(spec)

      expect(app).to receive(:call).with(env).once

      env[:plugin_name] = "foo"
      subject.call(env)
    end

    it "should specify the version if given" do
      spec = Gem::Specification.new
      expect(manager).to receive(:install_plugin).with(
        "foo", version: "bar", require: nil, sources: nil, verbose: false, env_local: nil).once.and_return(spec)

      expect(app).to receive(:call).with(env).once

      env[:plugin_name] = "foo"
      env[:plugin_version] = "bar"
      subject.call(env)
    end

    it "should specify the entrypoint if given" do
      spec = Gem::Specification.new
      expect(manager).to receive(:install_plugin).with(
        "foo", version: "bar", require: "baz", sources: nil, verbose: false, env_local: nil).once.and_return(spec)

      expect(app).to receive(:call).with(env).once

      env[:plugin_entry_point] = "baz"
      env[:plugin_name] = "foo"
      env[:plugin_version] = "bar"
      subject.call(env)
    end

    it "should specify the sources if given" do
      spec = Gem::Specification.new
      expect(manager).to receive(:install_plugin).with(
        "foo", version: nil, require: nil, sources: ["foo"], verbose: false, env_local: nil).once.and_return(spec)

      expect(app).to receive(:call).with(env).once

      env[:plugin_name] = "foo"
      env[:plugin_sources] = ["foo"]
      subject.call(env)
    end
  end

  describe "#recover" do
    it "should do nothing by default" do
      subject.recover(env)
    end

    context "with a successful plugin install" do
      let(:action_runner) { double("action_runner") }

      before do
        spec = Gem::Specification.new
        spec.name = "foo"
        allow(manager).to receive(:install_plugin).and_return(spec)

        env[:plugin_name] = "foo"
        subject.call(env)

        env[:action_runner] = action_runner
      end

      it "should uninstall the plugin" do
        expect(action_runner).to receive(:run).with(any_args) { |action, newenv|
          expect(newenv[:plugin_name]).to eql("foo")
        }

        subject.recover(env)
      end
    end
  end
end