2014-01-06 05:08:55 +00:00
|
|
|
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
|
|
|
|
Vagrant::Plugin::Manager.stub(instance: manager)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#call" do
|
|
|
|
it "should install the plugin" do
|
|
|
|
spec = Gem::Specification.new
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(manager).to receive(:install_plugin).with(
|
2014-01-06 18:55:34 +00:00
|
|
|
"foo", version: nil, require: nil, sources: nil, verbose: false).once.and_return(spec)
|
2014-01-06 05:08:55 +00:00
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(app).to receive(:call).with(env).once
|
2014-01-06 05:08:55 +00:00
|
|
|
|
|
|
|
env[:plugin_name] = "foo"
|
|
|
|
subject.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should specify the version if given" do
|
|
|
|
spec = Gem::Specification.new
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(manager).to receive(:install_plugin).with(
|
2014-01-06 18:55:34 +00:00
|
|
|
"foo", version: "bar", require: nil, sources: nil, verbose: false).once.and_return(spec)
|
2014-01-06 05:08:55 +00:00
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(app).to receive(:call).with(env).once
|
2014-01-06 05:08:55 +00:00
|
|
|
|
|
|
|
env[:plugin_name] = "foo"
|
|
|
|
env[:plugin_version] = "bar"
|
|
|
|
subject.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should specify the entrypoint if given" do
|
|
|
|
spec = Gem::Specification.new
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(manager).to receive(:install_plugin).with(
|
2014-01-06 18:55:34 +00:00
|
|
|
"foo", version: "bar", require: "baz", sources: nil, verbose: false).once.and_return(spec)
|
2014-01-06 05:08:55 +00:00
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(app).to receive(:call).with(env).once
|
2014-01-06 05:08:55 +00:00
|
|
|
|
|
|
|
env[:plugin_entry_point] = "baz"
|
|
|
|
env[:plugin_name] = "foo"
|
|
|
|
env[:plugin_version] = "bar"
|
|
|
|
subject.call(env)
|
|
|
|
end
|
2014-01-06 07:13:49 +00:00
|
|
|
|
|
|
|
it "should specify the sources if given" do
|
|
|
|
spec = Gem::Specification.new
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(manager).to receive(:install_plugin).with(
|
2014-01-06 18:55:34 +00:00
|
|
|
"foo", version: nil, require: nil, sources: ["foo"], verbose: false).once.and_return(spec)
|
2014-01-06 07:13:49 +00:00
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(app).to receive(:call).with(env).once
|
2014-01-06 07:13:49 +00:00
|
|
|
|
|
|
|
env[:plugin_name] = "foo"
|
|
|
|
env[:plugin_sources] = ["foo"]
|
|
|
|
subject.call(env)
|
|
|
|
end
|
2014-01-06 05:08:55 +00:00
|
|
|
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"
|
|
|
|
manager.stub(install_plugin: spec)
|
|
|
|
|
|
|
|
env[:plugin_name] = "foo"
|
|
|
|
subject.call(env)
|
|
|
|
|
|
|
|
env[:action_runner] = action_runner
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should uninstall the plugin" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(action_runner).to receive(:run).with { |action, newenv|
|
2014-01-06 05:08:55 +00:00
|
|
|
expect(newenv[:plugin_name]).to eql("foo")
|
2014-03-14 15:02:07 +00:00
|
|
|
}
|
2014-01-06 05:08:55 +00:00
|
|
|
|
|
|
|
subject.recover(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|