Raise an exception if a non-MachineState is returned
This commit is contained in:
parent
7bdf54923a
commit
8ad8f73846
|
@ -248,6 +248,10 @@ module Vagrant
|
|||
error_key(:machine_not_found)
|
||||
end
|
||||
|
||||
class MachineStateInvalid < VagrantError
|
||||
error_key(:machine_state_invalid)
|
||||
end
|
||||
|
||||
class MultiVMEnvironmentRequired < VagrantError
|
||||
status_code(5)
|
||||
error_key(:multi_vm_required)
|
||||
|
|
|
@ -277,7 +277,9 @@ module Vagrant
|
|||
#
|
||||
# @return [Symbol]
|
||||
def state
|
||||
@provider.state
|
||||
result = @provider.state
|
||||
raise Errors::MachineStateInvalid if !result.is_a?(MachineState)
|
||||
result
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -145,6 +145,12 @@ en:
|
|||
machine_not_found: |-
|
||||
The machine with the name '%{name}' was not found configured for
|
||||
this Vagrant environment.
|
||||
machine_state_invalid: |-
|
||||
An internal error has occurred! The provider of the machine you're
|
||||
trying to work with reported an invalid state. This is a bug with
|
||||
the provider you're using, and not with Vagrant itself or with
|
||||
any configuration you may have done. Please report this bug to
|
||||
the proper location.
|
||||
multi_vm_required: |-
|
||||
A multi-vm environment is required for name specification to this command.
|
||||
multi_vm_target_required: |-
|
||||
|
|
|
@ -385,10 +385,16 @@ describe Vagrant::Machine do
|
|||
|
||||
describe "state" do
|
||||
it "should query state from the provider" do
|
||||
state = :running
|
||||
state = Vagrant::MachineState.new(:id, "short", "long")
|
||||
|
||||
provider.should_receive(:state).and_return(state)
|
||||
instance.state.should == state
|
||||
instance.state.id.should == :id
|
||||
end
|
||||
|
||||
it "should raise an exception if a MachineState is not returned" do
|
||||
provider.should_receive(:state).and_return(:old_school)
|
||||
expect { instance.state }.
|
||||
to raise_error(Vagrant::Errors::MachineStateInvalid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue