tiny test refactor

This commit is contained in:
John Bender 2010-02-02 09:11:06 -08:00
parent d0f728b353
commit c0980d56bd
1 changed files with 18 additions and 20 deletions

View File

@ -183,45 +183,43 @@ class VMTest < Test::Unit::TestCase
end end
end end
context "suspending a vm" do context "suspending and resuming a vm" do
should "put the vm in a suspended state" do should "put the vm in a suspended state" do
saved_state_expectations(false) saved_state_expectation(false)
save_expectation
Hobo::VM.suspend Hobo::VM.suspend
end end
should "results in an error and exit if the vm is already in a saved state" do should "results in an error and exit if the vm is already in a saved state" do
saved_state_expectations(true) saved_state_expectation(true)
save_expectation
Hobo::VM.expects(:error_and_exit) Hobo::VM.expects(:error_and_exit)
Hobo::VM.suspend Hobo::VM.suspend
end end
def saved_state_expectations(saved)
@persisted_vm.expects(:saved?).returns(saved)
# In this case the exit, is ignored so the expectation of save_state on the persisted
# vm must be set
@persisted_vm.expects(:save_state).with(true)
end
end
context "resuming a vm" do
should "start a vm in a suspended state" do should "start a vm in a suspended state" do
start_state_expectaions(true) saved_state_expectation(true)
start_expectation
Hobo::VM.resume Hobo::VM.resume
end end
should "results in an error and exit if the vm is not in a saved state" do should "results in an error and exit if the vm is not in a saved state" do
start_state_expectaions(false) saved_state_expectation(false)
start_expectation
# In this case the exit, is ignored so the expectation of start on the persisted
# vm must be set
# TODO research the matter of mocking exit # TODO research the matter of mocking exit
Hobo::VM.expects(:error_and_exit) Hobo::VM.expects(:error_and_exit)
Hobo::VM.resume Hobo::VM.resume
end end
def start_state_expectaions(saved) def saved_state_expectation(saved)
@persisted_vm.expects(:saved?).returns(saved) @persisted_vm.expects(:saved?).returns(saved)
end
def save_expectation
@persisted_vm.expects(:save_state).with(true)
end
def start_expectation
Hobo::Env.persisted_vm.expects(:start).once.returns(true) Hobo::Env.persisted_vm.expects(:start).once.returns(true)
end end
end end