From ff7e9dc2ae3c2cc460c249aff58003140c3fa4cd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 Jul 2010 20:48:01 -0700 Subject: [PATCH] Get rid of ActionException usage in provisioners --- lib/vagrant/provisioners/chef.rb | 2 +- lib/vagrant/provisioners/chef_server.rb | 10 +++---- test/vagrant/provisioners/chef_server_test.rb | 29 ++++++++++--------- test/vagrant/provisioners/chef_test.rb | 8 ++--- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 2b958c329..22996e51d 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -72,7 +72,7 @@ module Vagrant Config.configures :chef, ChefConfig def prepare - raise Actions::ActionException.new(:chef_base_invalid_provisioner) + action_env.error!(:chef_base_invalid_provisioner) end def verify_binary(binary) diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index 2eba7e3d6..a4b1ee7f6 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -5,13 +5,11 @@ module Vagrant class ChefServer < Chef def prepare if env.config.chef.validation_key_path.nil? - raise Actions::ActionException.new(:chef_server_validation_key_required) + action_env.error!(:chef_server_validation_key_required) elsif !File.file?(validation_key_path) - raise Actions::ActionException.new(:chef_server_validation_key_doesnt_exist) - end - - if env.config.chef.chef_server_url.nil? - raise Actions::ActionException.new(:chef_server_url_required) + action_env.error!(:chef_server_validation_key_doesnt_exist) + elsif env.config.chef.chef_server_url.nil? + action_env.error!(:chef_server_url_required) end end diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index c3d6c6cc4..4bd4e1668 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -36,19 +36,20 @@ class ChefServerProvisionerTest < Test::Unit::TestCase @action.stubs(:env).returns(@env) - assert_nothing_raised { @action.prepare } + @action.prepare + assert !@action_env.error? end - should "raise an exception if validation_key_path is nil" do + should "eraise an exception if validation_key_path is nil" do @env = mock_environment do |config| config.chef.validation_key_path = nil end @action.stubs(:env).returns(@env) - assert_raises(Vagrant::Actions::ActionException) { - @action.prepare - } + @action.prepare + assert @action_env.error? + assert_equal :chef_server_validation_key_required, @action_env.error.first end should "not raise an exception if validation_key_path does exist" do @@ -60,7 +61,8 @@ class ChefServerProvisionerTest < Test::Unit::TestCase @action.stubs(:validation_key_path).returns("9") File.expects(:file?).with(@action.validation_key_path).returns(true) - assert_nothing_raised { @action.prepare } + @action.prepare + assert !@action_env.error? end should "raise an exception if validation_key_path doesn't exist" do @@ -72,9 +74,9 @@ class ChefServerProvisionerTest < Test::Unit::TestCase @action.stubs(:validation_key_path).returns("9") File.expects(:file?).with(@action.validation_key_path).returns(false) - assert_raises(Vagrant::Actions::ActionException) { - @action.prepare - } + @action.prepare + assert @action_env.error? + assert_equal :chef_server_validation_key_doesnt_exist, @action_env.error.first end should "not raise an exception if chef_server_url is set" do @@ -84,7 +86,8 @@ class ChefServerProvisionerTest < Test::Unit::TestCase @action.stubs(:env).returns(@env) - assert_nothing_raised { @action.prepare } + @action.prepare + assert !@action_env.error? end should "raise an exception if chef_server_url is nil" do @@ -94,9 +97,9 @@ class ChefServerProvisionerTest < Test::Unit::TestCase @action.stubs(:env).returns(@env) - assert_raises(Vagrant::Actions::ActionException) { - @action.prepare - } + @action.prepare + assert @action_env.error? + assert_equal :chef_server_url_required, @action_env.error.first end end diff --git a/test/vagrant/provisioners/chef_test.rb b/test/vagrant/provisioners/chef_test.rb index 6e98e1c57..32df5d159 100644 --- a/test/vagrant/provisioners/chef_test.rb +++ b/test/vagrant/provisioners/chef_test.rb @@ -11,10 +11,10 @@ class ChefProvisionerTest < Test::Unit::TestCase end context "preparing" do - should "raise an ActionException" do - assert_raises(Vagrant::Actions::ActionException) { - @action.prepare - } + should "error the environment" do + @action.prepare + assert @action_env.error? + assert_equal :chef_base_invalid_provisioner, @action_env.error.first end end