From c0980d56bda04e78473c48a23d0c4da253c363ca Mon Sep 17 00:00:00 2001 From: John Bender Date: Tue, 2 Feb 2010 09:11:06 -0800 Subject: [PATCH] tiny test refactor --- test/hobo/vm_test.rb | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/test/hobo/vm_test.rb b/test/hobo/vm_test.rb index bbcfea8a3..867f07b8f 100644 --- a/test/hobo/vm_test.rb +++ b/test/hobo/vm_test.rb @@ -183,45 +183,43 @@ class VMTest < Test::Unit::TestCase end end - context "suspending a vm" do + context "suspending and resuming a vm" do should "put the vm in a suspended state" do - saved_state_expectations(false) + saved_state_expectation(false) + save_expectation Hobo::VM.suspend end 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.suspend 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 - start_state_expectaions(true) + saved_state_expectation(true) + start_expectation Hobo::VM.resume end should "results in an error and exit if the vm is not in a saved state" do - start_state_expectaions(false) - - # In this case the exit, is ignored so the expectation of start on the persisted - # vm must be set + saved_state_expectation(false) + start_expectation # TODO research the matter of mocking exit Hobo::VM.expects(:error_and_exit) Hobo::VM.resume + end + + def saved_state_expectation(saved) + @persisted_vm.expects(:saved?).returns(saved) + end + + def save_expectation + @persisted_vm.expects(:save_state).with(true) end - def start_state_expectaions(saved) - @persisted_vm.expects(:saved?).returns(saved) + def start_expectation Hobo::Env.persisted_vm.expects(:start).once.returns(true) end end