diff --git a/lib/vagrant/actions/base.rb b/lib/vagrant/actions/base.rb index e6bd4e995..4104984c8 100644 --- a/lib/vagrant/actions/base.rb +++ b/lib/vagrant/actions/base.rb @@ -47,5 +47,7 @@ module Vagrant # @vm.invoke_callback(:after_oven, "more", "than", "one", "option") end end + + class ActionException < Exception; end end end diff --git a/lib/vagrant/actions/vm/package.rb b/lib/vagrant/actions/vm/package.rb index b920060a6..660722063 100644 --- a/lib/vagrant/actions/vm/package.rb +++ b/lib/vagrant/actions/vm/package.rb @@ -13,6 +13,12 @@ module Vagrant @temp_path = nil end + def prepare + @include_files.each do |file| + raise ActionException.new("#{file} does not exist") unless File.exists?(file) + end + end + def execute! compress clean diff --git a/test/vagrant/actions/vm/package_test.rb b/test/vagrant/actions/vm/package_test.rb index 23676a2f1..1af45bfc3 100644 --- a/test/vagrant/actions/vm/package_test.rb +++ b/test/vagrant/actions/vm/package_test.rb @@ -4,7 +4,6 @@ class PackageActionTest < Test::Unit::TestCase setup do @wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", []) mock_config - @temp_path = "temp_path" @action.temp_path = @temp_path end @@ -123,4 +122,23 @@ class PackageActionTest < Test::Unit::TestCase assert foo.equal?(@action.temp_path) end end + + context "preparing the action" do + setup do + @include_files = ['fooiest', 'booiest'] + @action = mock_action(Vagrant::Actions::VM::Package, "bing", @include_files).last + end + + should "check that all the include files exist" do + @include_files.each do |file| + File.expects(:exists?).with(file).returns(true) + end + @action.prepare + end + + should "raise an exception when an include file does not exist" do + File.expects(:exists?).once.returns(false) + assert_raises(Vagrant::Actions::ActionException) { @action.prepare } + end + end end