core: Add usable? check to providers

This commit is contained in:
Mitchell Hashimoto 2014-04-10 09:58:39 -07:00
parent f2bd6988b6
commit bc2e3727a9
2 changed files with 19 additions and 0 deletions

View File

@ -9,6 +9,21 @@ module Vagrant
class Provider class Provider
include CapabilityHost include CapabilityHost
# This is called early, before a machine is instantiated, to check
# if this provider is usable. This should return true or false.
#
# If raise_error is true, then instead of returning false, this
# should raise an error with a helpful message about why this
# provider cannot be used.
#
# @param [Boolean] raise_error If true, raise exception if not usable.
# @return [Boolean]
def self.usable?(raise_error=false)
# Return true by default for backwards compat since this was
# introduced long after providers were being written.
true
end
# Initialize the provider to represent the given machine. # Initialize the provider to represent the given machine.
# #
# @param [Vagrant::Machine] machine The machine that this provider # @param [Vagrant::Machine] machine The machine that this provider

View File

@ -8,6 +8,10 @@ describe Vagrant::Plugin::V2::Provider do
subject { instance } subject { instance }
it "should be usable by default" do
expect(described_class).to be_usable
end
it "should return nil by default for actions" do it "should return nil by default for actions" do
expect(instance.action(:whatever)).to be_nil expect(instance.action(:whatever)).to be_nil
end end