commands/plugin: fix plugin existence middleware, add tests

This commit is contained in:
Mitchell Hashimoto 2014-01-05 20:57:55 -08:00
parent 5fe2994005
commit aeb0d1a480
2 changed files with 32 additions and 1 deletions

View File

@ -11,7 +11,7 @@ module VagrantPlugins
end
def call(env)
installed = Vagrant::Plugin::Manager.instance.installed_specs
installed = Vagrant::Plugin::Manager.instance.installed_plugins
if !installed.has_key?(env[:plugin_name])
raise Vagrant::Errors::PluginNotInstalled,
name: env[:plugin_name]

View File

@ -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