diff --git a/Gemfile b/Gemfile index 1e64aefe1..9df0d158a 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem "mario", "~> 0.0.6" # Gems required for testing only. To install run # gem bundle test group :test do + gem "rake" gem "contest", ">= 0.1.2" gem "mocha" gem "ruby-debug", ">= 0.10.3" if RUBY_VERSION < '1.9' diff --git a/lib/vagrant/action/vm/package.rb b/lib/vagrant/action/vm/package.rb index 3647890f0..afb338386 100644 --- a/lib/vagrant/action/vm/package.rb +++ b/lib/vagrant/action/vm/package.rb @@ -21,6 +21,13 @@ module Vagrant compress @app.call(env) + + cleanup if env.error? + end + + def cleanup + # Cleanup any packaged files if the packaging failed at some point. + File.delete(tar_path) if File.exist?(tar_path) end def verify_included_files diff --git a/test/test_helper.rb b/test/test_helper.rb index 142293ca1..776b6ba9e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,10 +1,3 @@ -begin - require File.expand_path('../.bundle/environment', __FILE__) -rescue LoadError - # Fallback on doing the resolve at runtime. - require "rubygems" -end - # ruby-debug, not necessary, but useful if we have it begin require 'ruby-debug' diff --git a/test/vagrant/action/vm/package_test.rb b/test/vagrant/action/vm/package_test.rb index 3e7fc7666..7e2a852b4 100644 --- a/test/vagrant/action/vm/package_test.rb +++ b/test/vagrant/action/vm/package_test.rb @@ -68,6 +68,7 @@ class PackageVMActionTest < Test::Unit::TestCase @instance.expects(:verify_included_files).in_sequence(seq).returns(true) @instance.expects(:compress).in_sequence(seq) @app.expects(:call).with(@env).in_sequence(seq) + @instance.expects(:cleanup).never @instance.call(@env) end @@ -88,6 +89,40 @@ class PackageVMActionTest < Test::Unit::TestCase assert @env.error? assert_equal :package_requires_export, @env.error.first end + + should "run cleanup if environment errors" do + seq = sequence("seq") + @instance.expects(:verify_included_files).in_sequence(seq).returns(true) + @instance.expects(:compress).in_sequence(seq) + @app.expects(:call).with(@env).in_sequence(seq) + @instance.expects(:cleanup).in_sequence(seq) + + @env.error!(:foo) + @instance.call(@env) + end + end + + context "cleaning up" do + setup do + File.stubs(:exist?).returns(false) + File.stubs(:delete) + + @instance.stubs(:tar_path).returns("foo") + end + + should "do nothing if the file doesn't exist" do + File.expects(:exist?).with(@instance.tar_path).returns(false) + File.expects(:delete).never + + @instance.cleanup + end + + should "delete the packaged box if it exists" do + File.expects(:exist?).returns(true) + File.expects(:delete).with(@instance.tar_path).once + + @instance.cleanup + end end context "verifying included files" do diff --git a/vagrant.gemspec b/vagrant.gemspec index f0c0eca3c..8ce30253a 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.authors = ["Mitchell Hashimoto", "John Bender"] - s.date = %q{2010-07-17} + s.date = %q{2010-07-18} s.default_executable = %q{vagrant} s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"] @@ -208,94 +208,94 @@ Gem::Specification.new do |s| s.homepage = %q{http://github.com/mitchellh/vagrant} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.6} + s.rubygems_version = %q{1.3.7} s.summary = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.test_files = [ "test/test_helper.rb", - "test/vagrant/vm_test.rb", - "test/vagrant/command_test.rb", + "test/vagrant/action/box/destroy_test.rb", + "test/vagrant/action/box/download_test.rb", + "test/vagrant/action/box/unpackage_test.rb", + "test/vagrant/action/box/verify_test.rb", + "test/vagrant/action/builder_test.rb", + "test/vagrant/action/env/error_halt_test.rb", + "test/vagrant/action/env/set_test.rb", "test/vagrant/action/environment_test.rb", "test/vagrant/action/exception_catcher_test.rb", - "test/vagrant/action/box/verify_test.rb", - "test/vagrant/action/box/destroy_test.rb", - "test/vagrant/action/box/unpackage_test.rb", - "test/vagrant/action/box/download_test.rb", - "test/vagrant/action/vm/suspend_test.rb", "test/vagrant/action/vm/boot_test.rb", - "test/vagrant/action/vm/package_test.rb", - "test/vagrant/action/vm/share_folders_test.rb", - "test/vagrant/action/vm/forward_ports_helpers_test.rb", - "test/vagrant/action/vm/persist_test.rb", - "test/vagrant/action/vm/nfs_test.rb", - "test/vagrant/action/vm/clear_nfs_exports_test.rb", - "test/vagrant/action/vm/destroy_test.rb", - "test/vagrant/action/vm/halt_test.rb", - "test/vagrant/action/vm/clear_forwarded_ports_test.rb", "test/vagrant/action/vm/check_guest_additions_test.rb", - "test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb", - "test/vagrant/action/vm/import_test.rb", - "test/vagrant/action/vm/nfs_helpers_test.rb", - "test/vagrant/action/vm/customize_test.rb", - "test/vagrant/action/vm/network_test.rb", - "test/vagrant/action/vm/export_test.rb", - "test/vagrant/action/vm/provision_test.rb", - "test/vagrant/action/vm/clear_shared_folders_test.rb", "test/vagrant/action/vm/clean_machine_folder_test.rb", - "test/vagrant/action/vm/resume_test.rb", - "test/vagrant/action/vm/match_mac_address_test.rb", + "test/vagrant/action/vm/clear_forwarded_ports_test.rb", + "test/vagrant/action/vm/clear_nfs_exports_test.rb", + "test/vagrant/action/vm/clear_shared_folders_test.rb", + "test/vagrant/action/vm/customize_test.rb", + "test/vagrant/action/vm/destroy_test.rb", + "test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb", + "test/vagrant/action/vm/export_test.rb", + "test/vagrant/action/vm/forward_ports_helpers_test.rb", "test/vagrant/action/vm/forward_ports_test.rb", - "test/vagrant/action/builder_test.rb", - "test/vagrant/action/env/set_test.rb", - "test/vagrant/action/env/error_halt_test.rb", - "test/vagrant/environment_test.rb", - "test/vagrant/util_test.rb", + "test/vagrant/action/vm/halt_test.rb", + "test/vagrant/action/vm/import_test.rb", + "test/vagrant/action/vm/match_mac_address_test.rb", + "test/vagrant/action/vm/network_test.rb", + "test/vagrant/action/vm/nfs_helpers_test.rb", + "test/vagrant/action/vm/nfs_test.rb", + "test/vagrant/action/vm/package_test.rb", + "test/vagrant/action/vm/persist_test.rb", + "test/vagrant/action/vm/provision_test.rb", + "test/vagrant/action/vm/resume_test.rb", + "test/vagrant/action/vm/share_folders_test.rb", + "test/vagrant/action/vm/suspend_test.rb", + "test/vagrant/action_test.rb", + "test/vagrant/active_list_test.rb", "test/vagrant/box_test.rb", "test/vagrant/busy_test.rb", - "test/vagrant/provisioners/base_test.rb", - "test/vagrant/provisioners/chef_test.rb", - "test/vagrant/provisioners/chef_server_test.rb", - "test/vagrant/provisioners/chef_solo_test.rb", - "test/vagrant/systems/linux_test.rb", - "test/vagrant/config_test.rb", - "test/vagrant/hosts/base_test.rb", - "test/vagrant/hosts/linux_test.rb", - "test/vagrant/hosts/bsd_test.rb", - "test/vagrant/active_list_test.rb", + "test/vagrant/command_test.rb", "test/vagrant/commands/base_test.rb", - "test/vagrant/commands/reload_test.rb", - "test/vagrant/commands/ssh_config_test.rb", - "test/vagrant/commands/suspend_test.rb", - "test/vagrant/commands/package_test.rb", - "test/vagrant/commands/status_test.rb", - "test/vagrant/commands/init_test.rb", - "test/vagrant/commands/destroy_test.rb", - "test/vagrant/commands/halt_test.rb", - "test/vagrant/commands/box/remove_test.rb", "test/vagrant/commands/box/add_test.rb", "test/vagrant/commands/box/list_test.rb", - "test/vagrant/commands/up_test.rb", + "test/vagrant/commands/box/remove_test.rb", + "test/vagrant/commands/destroy_test.rb", + "test/vagrant/commands/halt_test.rb", + "test/vagrant/commands/init_test.rb", + "test/vagrant/commands/package_test.rb", "test/vagrant/commands/provision_test.rb", + "test/vagrant/commands/reload_test.rb", "test/vagrant/commands/resume_test.rb", + "test/vagrant/commands/ssh_config_test.rb", "test/vagrant/commands/ssh_test.rb", - "test/vagrant/resource_logger_test.rb", + "test/vagrant/commands/status_test.rb", + "test/vagrant/commands/suspend_test.rb", + "test/vagrant/commands/up_test.rb", + "test/vagrant/config_test.rb", "test/vagrant/downloaders/base_test.rb", "test/vagrant/downloaders/file_test.rb", "test/vagrant/downloaders/http_test.rb", + "test/vagrant/environment_test.rb", + "test/vagrant/hosts/base_test.rb", + "test/vagrant/hosts/bsd_test.rb", + "test/vagrant/hosts/linux_test.rb", + "test/vagrant/provisioners/base_test.rb", + "test/vagrant/provisioners/chef_server_test.rb", + "test/vagrant/provisioners/chef_solo_test.rb", + "test/vagrant/provisioners/chef_test.rb", + "test/vagrant/resource_logger_test.rb", + "test/vagrant/ssh_session_test.rb", + "test/vagrant/ssh_test.rb", + "test/vagrant/systems/linux_test.rb", + "test/vagrant/util/plain_logger_test.rb", + "test/vagrant/util/platform_test.rb", "test/vagrant/util/stacked_proc_runner_test.rb", "test/vagrant/util/template_renderer_test.rb", "test/vagrant/util/translator_test.rb", - "test/vagrant/util/platform_test.rb", - "test/vagrant/util/plain_logger_test.rb", - "test/vagrant/ssh_session_test.rb", - "test/vagrant/action_test.rb", - "test/vagrant/ssh_test.rb" + "test/vagrant/util_test.rb", + "test/vagrant/vm_test.rb" ] if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, ["~> 0.7.3"]) s.add_runtime_dependency(%q, [">= 2.0.19"]) s.add_runtime_dependency(%q, [">= 1.0.2"])