From cbcb8776246039e6e0ae0a6b8cdcb859d5cd1e9c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 20 Feb 2010 22:58:39 -0800 Subject: [PATCH] Compression tests for packaging --- test/vagrant/actions/package_test.rb | 41 +++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/test/vagrant/actions/package_test.rb b/test/vagrant/actions/package_test.rb index 879c0e414..7bf6c6dcc 100644 --- a/test/vagrant/actions/package_test.rb +++ b/test/vagrant/actions/package_test.rb @@ -55,5 +55,44 @@ class PackageActionTest < Test::Unit::TestCase end end - # TODO test compression once its finished + context "compression" do + setup do + @tar_path = "foo" + @action.stubs(:tar_path).returns(@tar_path) + + @pwd = "bar" + FileUtils.stubs(:pwd).returns(@pwd) + FileUtils.stubs(:cd) + + @tar = mock("tar") + Tar.stubs(:open).yields(@tar) + end + + should "open the tar file with the tar path properly" do + Tar.expects(:open).with(@tar_path, File::CREAT | File::WRONLY, 0644, Tar::GNU).once + @action.compress + end + + #---------------------------------------------------------------- + # Methods below this comment test the block yielded by Tar.open + #---------------------------------------------------------------- + should "cd to the directory and append the directory" do + compress_seq = sequence("compress_seq") + FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq) + FileUtils.expects(:cd).with(@action.to).in_sequence(compress_seq) + @tar.expects(:append_tree).with(@action.name).in_sequence(compress_seq) + FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq) + @action.compress + end + + should "pop back to the current directory even if an exception is raised" do + cd_seq = sequence("cd_seq") + FileUtils.expects(:cd).with(@action.to).raises(Exception).in_sequence(cd_seq) + FileUtils.expects(:cd).with(@pwd).in_sequence(cd_seq) + + assert_raises(Exception) { + @action.compress + } + end + end end