Unit tests for each error_and_exit now that the message is testable
This commit is contained in:
parent
3c2e1bd80a
commit
18f761b015
|
@ -14,7 +14,7 @@ module Vagrant
|
||||||
def init(default_box=nil)
|
def init(default_box=nil)
|
||||||
rootfile_path = File.join(Dir.pwd, Env::ROOTFILE_NAME)
|
rootfile_path = File.join(Dir.pwd, Env::ROOTFILE_NAME)
|
||||||
if File.exist?(rootfile_path)
|
if File.exist?(rootfile_path)
|
||||||
error_and_exit(:rootfile_already_exists, :rootfile => Env::ROOTFILE_NAME)
|
error_and_exit(:rootfile_already_exists)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Copy over the rootfile template into this directory
|
# Copy over the rootfile template into this directory
|
||||||
|
|
|
@ -128,7 +128,7 @@ module Vagrant
|
||||||
|
|
||||||
def require_root_path
|
def require_root_path
|
||||||
if !root_path
|
if !root_path
|
||||||
error_and_exit(:rootfile_not_found, :rootfile => ROOTFILE_NAME)
|
error_and_exit(:rootfile_not_found)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
already be created, but unfortunately this vagrant still appears to
|
already be created, but unfortunately this vagrant still appears to
|
||||||
have no box! You can setup the environment by setting up your
|
have no box! You can setup the environment by setting up your
|
||||||
<%= Vagrant::Env::ROOTFILE_NAME %> and running `vagrant up`"
|
<%= 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.)"
|
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
|
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."
|
root."
|
||||||
:virtualbox_invalid_version: "Vagrant has detected that you have VirtualBox version <%= version %> installed!
|
: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
|
Vagrant requires that you use at least VirtualBox version 3.1. Please install
|
||||||
|
|
|
@ -68,7 +68,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error and exit if the directory exists" do
|
should "error and exit if the directory exists" do
|
||||||
File.expects(:directory?).returns(true)
|
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
|
@action.setup_box_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ class BootActionTest < Test::Unit::TestCase
|
||||||
fail_boot_seq = sequence("fail_boot_seq")
|
fail_boot_seq = sequence("fail_boot_seq")
|
||||||
@action.expects(:boot).once.in_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(: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!
|
@action.execute!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,7 @@ class MoveHardDriveActionTest < Test::Unit::TestCase
|
||||||
context "execution" do
|
context "execution" do
|
||||||
should "error and exit if the vm is not powered off" do
|
should "error and exit if the vm is not powered off" do
|
||||||
@mock_vm.expects(:powered_off?).returns(false)
|
@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!
|
@action.execute!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error and exit if a rootfile already exists" do
|
should "error and exit if a rootfile already exists" do
|
||||||
File.expects(:exist?).with(@rootfile_path).returns(true)
|
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
|
Vagrant::Commands.init
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error and exit if the VM is not powered off" do
|
should "error and exit if the VM is not powered off" do
|
||||||
@persisted_vm.stubs(:powered_off?).returns(false)
|
@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
|
@persisted_vm.expects(:package).never
|
||||||
Vagrant::Commands.package
|
Vagrant::Commands.package
|
||||||
end
|
end
|
||||||
|
@ -216,12 +216,12 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
Vagrant::Commands.box(["add"])
|
Vagrant::Commands.box(["add"])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "error and exit if the first argument is not 'add' or 'remove'" do
|
should "error and exit if the first argument is not a valid subcommand" do
|
||||||
Vagrant::Commands.expects(:error_and_exit).once
|
Vagrant::Commands.expects(:error_and_exit).with(:command_box_invalid).once
|
||||||
Vagrant::Commands.box(["foo"])
|
Vagrant::Commands.box(["foo"])
|
||||||
end
|
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 = ["add", "remove"]
|
||||||
|
|
||||||
commands.each do |command|
|
commands.each do |command|
|
||||||
|
@ -272,7 +272,7 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error and exit if the box doesn't exist" do
|
should "error and exit if the box doesn't exist" do
|
||||||
Vagrant::Box.expects(:find).returns(nil)
|
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)
|
Vagrant::Commands.box_remove(@name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,20 +29,21 @@ class EnvTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "error and exit if VirtualBox is not installed or detected" do
|
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)
|
VirtualBox::Command.expects(:version).returns(nil)
|
||||||
Vagrant::Env.check_virtualbox!
|
Vagrant::Env.check_virtualbox!
|
||||||
end
|
end
|
||||||
|
|
||||||
should "error and exit if VirtualBox is lower than version 3.1" do
|
should "error and exit if VirtualBox is lower than version 3.1" do
|
||||||
Vagrant::Env.expects(:error_and_exit).once
|
version = "3.0.12r1041"
|
||||||
VirtualBox::Command.expects(:version).returns("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!
|
Vagrant::Env.check_virtualbox!
|
||||||
end
|
end
|
||||||
|
|
||||||
should "error and exit if the the vboxconfig is not set" do
|
should "error and exit if the the vboxconfig is not set" do
|
||||||
VirtualBox::Global.expects(:vboxconfig?).returns(false)
|
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!
|
Vagrant::Env.check_virtualbox!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -60,7 +61,7 @@ class EnvTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error and exit if no persisted VM was found" do
|
should "error and exit if no persisted VM was found" do
|
||||||
assert_nil Vagrant::Env.persisted_vm
|
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
|
Vagrant::Env.require_persisted_vm
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -413,7 +414,7 @@ class EnvTest < Test::Unit::TestCase
|
||||||
context "requiring root_path" do
|
context "requiring root_path" do
|
||||||
should "error and exit if no root_path is set" do
|
should "error and exit if no root_path is set" do
|
||||||
Vagrant::Env.expects(:root_path).returns(nil)
|
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
|
Vagrant::Env.require_root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ class SshTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error and exit if a Net::SSH::AuthenticationFailed is raised" do
|
should "error and exit if a Net::SSH::AuthenticationFailed is raised" do
|
||||||
Vagrant::SSH.expects(:execute).raises(Net::SSH::AuthenticationFailed)
|
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?
|
Vagrant::SSH.up?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue