Create the MachineState class

This commit is contained in:
Mitchell Hashimoto 2013-01-21 11:25:28 -06:00
parent cfe55eb57f
commit 7bdf54923a
3 changed files with 72 additions and 0 deletions

View File

@ -75,6 +75,7 @@ module Vagrant
autoload :Guest, 'vagrant/guest'
autoload :Hosts, 'vagrant/hosts'
autoload :Machine, 'vagrant/machine'
autoload :MachineState, 'vagrant/machine_state'
autoload :Plugin, 'vagrant/plugin'
autoload :TestHelpers, 'vagrant/test_helpers'
autoload :UI, 'vagrant/ui'

View File

@ -0,0 +1,45 @@
module Vagrant
# This represents the state of a given machine. This is a very basic
# class that simply stores a short and long description of the state
# of a machine.
#
# The state also stores a state "id" which ca be used as a unique
# identifier for a state. This should be a symbol. This allows internal
# code to compare state such as ":not_created" instead of using
# string comparison.
#
# The short description should be a single word description of the
# state of the machine such as "running" or "not created".
#
# The long description can span multiple lines describing what the
# state actually means.
class MachineState
# Unique ID for this state.
#
# @return [Symbol]
attr_reader :id
# Short description for this state.
#
# @return [String]
attr_reader :short_description
# Long description for this state.
#
# @return [String]
attr_reader :long_description
# Creates a new instance to represent the state of a machine.
#
# @param [Symbol] id Unique identifier for this state.
# @param [String] short Short (preferably one-word) description of
# the state.
# @param [String] long Long description (can span multiple lines)
# of the state.
def initialize(id, short, long)
@id = id
@short_description = short
@long_description = long
end
end
end

View File

@ -0,0 +1,26 @@
require "pathname"
require File.expand_path("../../base", __FILE__)
describe Vagrant::MachineState do
include_context "unit"
let(:id) { :some_state }
let(:short) { "foo" }
let(:long) { "I am a longer foo" }
it "should give access to the id" do
instance = described_class.new(id, short, long)
instance.id.should == id
end
it "should give access to the short description" do
instance = described_class.new(id, short, long)
instance.short_description.should == short
end
it "should give access to the long description" do
instance = described_class.new(id, short, long)
instance.long_description.should == long
end
end