From c1e0504c66fb194092dd8e6f4cacf594405f8216 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 31 Dec 2010 21:59:03 -0600 Subject: [PATCH] Improve the file downloader test to use a real file --- test/vagrant/downloaders/file_test.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/vagrant/downloaders/file_test.rb b/test/vagrant/downloaders/file_test.rb index 70180d28a..271e01e6b 100644 --- a/test/vagrant/downloaders/file_test.rb +++ b/test/vagrant/downloaders/file_test.rb @@ -17,11 +17,25 @@ class FileDownloaderTest < Test::Unit::TestCase end context "downloading" do + setup do + clean_paths + end + should "cp the file" do - path = '/path' - @tempfile.expects(:path).returns(path) - FileUtils.expects(:cp).with(@uri, path) - @downloader.download!(@uri, @tempfile) + uri = tmp_path.join("foo_source") + dest = tmp_path.join("foo_dest") + + # Create the source file, then "download" it + File.open(uri, "w+") { |f| f.write("FOO") } + File.open(dest, "w+") do |dest_file| + @downloader.download!(uri, dest_file) + end + + # Finally, verify the destination file was properly created + assert File.file?(dest) + File.open(dest) do |f| + assert_equal "FOO", f.read + end end end