diff --git a/plugins/commands/plugin/action/plugin_exists_check.rb b/plugins/commands/plugin/action/plugin_exists_check.rb index 6616abf0e..7a369976e 100644 --- a/plugins/commands/plugin/action/plugin_exists_check.rb +++ b/plugins/commands/plugin/action/plugin_exists_check.rb @@ -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] diff --git a/test/unit/plugins/commands/plugin/action/plugin_exists_check_test.rb b/test/unit/plugins/commands/plugin/action/plugin_exists_check_test.rb new file mode 100644 index 000000000..3a442e9ae --- /dev/null +++ b/test/unit/plugins/commands/plugin/action/plugin_exists_check_test.rb @@ -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