Unit tests for each error_and_exit now that the message is testable

This commit is contained in:
Mitchell Hashimoto 2010-03-17 21:15:48 -07:00
parent 3c2e1bd80a
commit 18f761b015
9 changed files with 22 additions and 21 deletions

View File

@ -14,7 +14,7 @@ module Vagrant
def init(default_box=nil)
rootfile_path = File.join(Dir.pwd, Env::ROOTFILE_NAME)
if File.exist?(rootfile_path)
error_and_exit(:rootfile_already_exists, :rootfile => Env::ROOTFILE_NAME)
error_and_exit(:rootfile_already_exists)
end
# Copy over the rootfile template into this directory

View File

@ -128,7 +128,7 @@ module Vagrant
def require_root_path
if !root_path
error_and_exit(:rootfile_not_found, :rootfile => ROOTFILE_NAME)
error_and_exit(:rootfile_not_found)
end
end

View File

@ -18,11 +18,11 @@
already be created, but unfortunately this vagrant still appears to
have no box! You can setup the environment by setting up your
<%= Vagrant::Env::ROOTFILE_NAME %> and running `vagrant up`"
:rootfile_already_exists: "It looks like this directory is already setup for vagrant! (A <%= rootfile %>
:rootfile_already_exists: "It looks like this directory is already setup for vagrant! (A <%= Vagrant::Env::ROOTFILE_NAME %>
already exists.)"
:rootfile_not_found: "A `<%= rootfile %>` was not found! This file is required for vagrant to run
:rootfile_not_found: "A `<%= Vagrant::Env::ROOTFILE_NAME %>` was not found! This file is required for vagrant to run
since it describes the expected environment that vagrant is supposed
to manage. Please create a `<%= rootfile %>` and place it in your project
to manage. Please create a `<%= Vagrant::Env::ROOTFILE_NAME %>` and place it in your project
root."
:virtualbox_invalid_version: "Vagrant has detected that you have VirtualBox version <%= version %> installed!
Vagrant requires that you use at least VirtualBox version 3.1. Please install

View File

@ -68,7 +68,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
should "error and exit if the directory exists" do
File.expects(:directory?).returns(true)
@action.expects(:error_and_exit).once
@action.expects(:error_and_exit).with(:box_already_exists, :box_name => @runner.name).once
@action.setup_box_dir
end

View File

@ -27,7 +27,7 @@ class BootActionTest < Test::Unit::TestCase
fail_boot_seq = sequence("fail_boot_seq")
@action.expects(:boot).once.in_sequence(fail_boot_seq)
@action.expects(:wait_for_boot).returns(false).in_sequence(fail_boot_seq)
@action.expects(:error_and_exit).once.in_sequence(fail_boot_seq)
@action.expects(:error_and_exit).with(:vm_failed_to_boot).once.in_sequence(fail_boot_seq)
@action.execute!
end
end

View File

@ -28,7 +28,7 @@ class MoveHardDriveActionTest < Test::Unit::TestCase
context "execution" do
should "error and exit if the vm is not powered off" do
@mock_vm.expects(:powered_off?).returns(false)
@action.expects(:error_and_exit).once
@action.expects(:error_and_exit).with(:vm_power_off_to_move_hd).once
@action.execute!
end

View File

@ -22,7 +22,7 @@ class CommandsTest < Test::Unit::TestCase
should "error and exit if a rootfile already exists" do
File.expects(:exist?).with(@rootfile_path).returns(true)
Vagrant::Commands.expects(:error_and_exit).once
Vagrant::Commands.expects(:error_and_exit).with(:rootfile_already_exists).once
Vagrant::Commands.init
end
@ -180,7 +180,7 @@ class CommandsTest < Test::Unit::TestCase
should "error and exit if the VM is not powered off" do
@persisted_vm.stubs(:powered_off?).returns(false)
Vagrant::Commands.expects(:error_and_exit).once
Vagrant::Commands.expects(:error_and_exit).with(:vm_power_off_to_package).once
@persisted_vm.expects(:package).never
Vagrant::Commands.package
end
@ -216,12 +216,12 @@ class CommandsTest < Test::Unit::TestCase
Vagrant::Commands.box(["add"])
end
should "error and exit if the first argument is not 'add' or 'remove'" do
Vagrant::Commands.expects(:error_and_exit).once
should "error and exit if the first argument is not a valid subcommand" do
Vagrant::Commands.expects(:error_and_exit).with(:command_box_invalid).once
Vagrant::Commands.box(["foo"])
end
should "not error and exit if the first argument is 'add' or 'remove'" do
should "not error and exit if the first argument is a valid subcommand" do
commands = ["add", "remove"]
commands.each do |command|
@ -272,7 +272,7 @@ class CommandsTest < Test::Unit::TestCase
should "error and exit if the box doesn't exist" do
Vagrant::Box.expects(:find).returns(nil)
Vagrant::Commands.expects(:error_and_exit).once
Vagrant::Commands.expects(:error_and_exit).with(:box_remove_doesnt_exist).once
Vagrant::Commands.box_remove(@name)
end

View File

@ -29,20 +29,21 @@ class EnvTest < Test::Unit::TestCase
end
should "error and exit if VirtualBox is not installed or detected" do
Vagrant::Env.expects(:error_and_exit).once
Vagrant::Env.expects(:error_and_exit).with(:virtualbox_not_detected).once
VirtualBox::Command.expects(:version).returns(nil)
Vagrant::Env.check_virtualbox!
end
should "error and exit if VirtualBox is lower than version 3.1" do
Vagrant::Env.expects(:error_and_exit).once
VirtualBox::Command.expects(:version).returns("3.0.12r1041")
version = "3.0.12r1041"
Vagrant::Env.expects(:error_and_exit).with(:virtualbox_invalid_version, :version => version.to_s).once
VirtualBox::Command.expects(:version).returns(version)
Vagrant::Env.check_virtualbox!
end
should "error and exit if the the vboxconfig is not set" do
VirtualBox::Global.expects(:vboxconfig?).returns(false)
Vagrant::Env.expects(:error_and_exit).once
Vagrant::Env.expects(:error_and_exit).with(:virtualbox_xml_not_detected).once
Vagrant::Env.check_virtualbox!
end
end
@ -60,7 +61,7 @@ class EnvTest < Test::Unit::TestCase
should "error and exit if no persisted VM was found" do
assert_nil Vagrant::Env.persisted_vm
Vagrant::Env.expects(:error_and_exit).once
Vagrant::Env.expects(:error_and_exit).with(:environment_not_created).once
Vagrant::Env.require_persisted_vm
end
@ -413,7 +414,7 @@ class EnvTest < Test::Unit::TestCase
context "requiring root_path" do
should "error and exit if no root_path is set" do
Vagrant::Env.expects(:root_path).returns(nil)
Vagrant::Env.expects(:error_and_exit).once
Vagrant::Env.expects(:error_and_exit).with(:rootfile_not_found).once
Vagrant::Env.require_root_path
end

View File

@ -107,7 +107,7 @@ class SshTest < Test::Unit::TestCase
should "error and exit if a Net::SSH::AuthenticationFailed is raised" do
Vagrant::SSH.expects(:execute).raises(Net::SSH::AuthenticationFailed)
Vagrant::SSH.expects(:error_and_exit).once
Vagrant::SSH.expects(:error_and_exit).with(:vm_ssh_auth_failed).once
Vagrant::SSH.up?
end
end