From 12b769ce147fc6916c10fcabeffba789b93974c4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 3 Oct 2010 18:48:41 -0700 Subject: [PATCH] Removed final global test helper from test/test_helper.rb --- CHANGELOG.md | 1 + lib/vagrant/test_helpers.rb | 13 +++++++++++++ test/test_helper.rb | 9 --------- test/vagrant/downloaders/file_test.rb | 2 +- test/vagrant/downloaders/http_test.rb | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b9dae3233..06ef62e4afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.6.4 (unreleased) + - Added method to `TestHelpers` to assist with testing new downloaders. - `up --no-provision` works again. This disables provisioning during the boot process. - Action warden doesn't do recovery process on `SystemExit` exceptions, diff --git a/lib/vagrant/test_helpers.rb b/lib/vagrant/test_helpers.rb index 58c3836ff77..3928b4c925d 100644 --- a/lib/vagrant/test_helpers.rb +++ b/lib/vagrant/test_helpers.rb @@ -55,6 +55,19 @@ def vagrant_box(name) result end + # Returns an instantiated downloader with a mocked tempfile + # which can be passed into it. + # + # @param [Class] klass The downloader class + # @return [Array] Returns an array of `downloader` `tempfile` + def vagrant_mock_downloader(klass) + tempfile = mock("tempfile") + tempfile.stubs(:write) + + _, env = action_env + [klass.new(env), tempfile] + end + # Returns a blank app (callable) and action environment with the # given vagrant environment. This allows for testing of middlewares. def action_env(v_env = nil) diff --git a/test/test_helper.rb b/test/test_helper.rb index 35a5036b4f9..d98ec2ecba5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,14 +22,5 @@ class Test::Unit::TestCase include Vagrant::TestHelpers - - # Sets up the mocks and stubs for a downloader - def mock_downloader(downloader_klass) - tempfile = mock("tempfile") - tempfile.stubs(:write) - - _, env = action_env - [downloader_klass.new(env), tempfile] - end end diff --git a/test/vagrant/downloaders/file_test.rb b/test/vagrant/downloaders/file_test.rb index 5d3ac9355fa..70180d28a2f 100644 --- a/test/vagrant/downloaders/file_test.rb +++ b/test/vagrant/downloaders/file_test.rb @@ -2,7 +2,7 @@ class FileDownloaderTest < Test::Unit::TestCase setup do - @downloader, @tempfile = mock_downloader(Vagrant::Downloaders::File) + @downloader, @tempfile = vagrant_mock_downloader(Vagrant::Downloaders::File) @uri = "foo.box" end diff --git a/test/vagrant/downloaders/http_test.rb b/test/vagrant/downloaders/http_test.rb index 6bf6c8f63fd..65ee9d219c4 100644 --- a/test/vagrant/downloaders/http_test.rb +++ b/test/vagrant/downloaders/http_test.rb @@ -2,7 +2,7 @@ class HttpDownloaderTest < Test::Unit::TestCase setup do - @downloader, @tempfile = mock_downloader(Vagrant::Downloaders::HTTP) + @downloader, @tempfile = vagrant_mock_downloader(Vagrant::Downloaders::HTTP) @downloader.stubs(:report_progress) @downloader.stubs(:complete_progress) @uri = "http://google.com/"