commands/plugin: fix plugin existence middleware, add tests
This commit is contained in:
parent
5fe2994005
commit
aeb0d1a480
|
@ -11,7 +11,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
installed = Vagrant::Plugin::Manager.instance.installed_specs
|
installed = Vagrant::Plugin::Manager.instance.installed_plugins
|
||||||
if !installed.has_key?(env[:plugin_name])
|
if !installed.has_key?(env[:plugin_name])
|
||||||
raise Vagrant::Errors::PluginNotInstalled,
|
raise Vagrant::Errors::PluginNotInstalled,
|
||||||
name: env[:plugin_name]
|
name: env[:plugin_name]
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
require File.expand_path("../../../../../base", __FILE__)
|
||||||
|
|
||||||
|
describe VagrantPlugins::CommandPlugin::Action::PluginExistsCheck do
|
||||||
|
let(:app) { lambda {} }
|
||||||
|
let(:env) { {} }
|
||||||
|
|
||||||
|
let(:manager) { double("manager") }
|
||||||
|
|
||||||
|
subject { described_class.new(app, env) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Vagrant::Plugin::Manager.stub(instance: manager)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should raise an exception if the plugin doesn't exist" do
|
||||||
|
manager.stub(installed_plugins: { "foo" => {} })
|
||||||
|
app.should_not_receive(:call)
|
||||||
|
|
||||||
|
env[:plugin_name] = "bar"
|
||||||
|
expect { subject.call(env) }.
|
||||||
|
to raise_error(Vagrant::Errors::PluginNotInstalled)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should call the app if the plugin is installed" do
|
||||||
|
manager.stub(installed_plugins: { "bar" => {} })
|
||||||
|
app.should_receive(:call).once.with(env)
|
||||||
|
|
||||||
|
env[:plugin_name] = "bar"
|
||||||
|
subject.call(env)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue