From 26c12a9a177373855895dfe509dbd545d800c098 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Apr 2010 14:03:50 -0700 Subject: [PATCH] Init subcommand is working --- lib/vagrant/commands/base.rb | 2 ++ lib/vagrant/commands/init.rb | 18 ++++++++++- test/vagrant/commands/base_test.rb | 2 +- test/vagrant/commands/init_test.rb | 51 ++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 test/vagrant/commands/init_test.rb diff --git a/lib/vagrant/commands/base.rb b/lib/vagrant/commands/base.rb index da81c2687..350123fb9 100644 --- a/lib/vagrant/commands/base.rb +++ b/lib/vagrant/commands/base.rb @@ -5,6 +5,8 @@ module Vagrant # This is the base command class which all sub-commands must # inherit from. class Base + include Util + attr_reader :env class < default_box)) + end end end end diff --git a/test/vagrant/commands/base_test.rb b/test/vagrant/commands/base_test.rb index 51fece2cd..c129b3896 100644 --- a/test/vagrant/commands/base_test.rb +++ b/test/vagrant/commands/base_test.rb @@ -1,6 +1,6 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') -class CommandsBastTest < Test::Unit::TestCase +class CommandsBaseTest < Test::Unit::TestCase setup do @klass = Vagrant::Commands::Base end diff --git a/test/vagrant/commands/init_test.rb b/test/vagrant/commands/init_test.rb new file mode 100644 index 000000000..fc7829947 --- /dev/null +++ b/test/vagrant/commands/init_test.rb @@ -0,0 +1,51 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class CommandsInitTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Commands::Init + + @env = mock_environment + @instance = @klass.new(@env) + end + + context "execute" do + # TODO + end + + context "creating the vagrantfile" do + setup do + @file = mock("file") + @file.stubs(:write) + File.stubs(:open).yields(@file) + @rootfile_path = File.join(Dir.pwd, Vagrant::Environment::ROOTFILE_NAME) + + Vagrant::Util::TemplateRenderer.stubs(:render) + end + + should "error and exit if a rootfile already exists" do + File.expects(:exist?).with(@rootfile_path).returns(true) + @instance.expects(:error_and_exit).with(:rootfile_already_exists).once + @instance.create_vagrantfile + end + + should "write to the rootfile path using the template renderer" do + result = "foo" + Vagrant::Util::TemplateRenderer.expects(:render).returns(result).once + @file.expects(:write).with(result).once + File.expects(:open).with(@rootfile_path, 'w+').yields(@file) + + @instance.create_vagrantfile + end + + should "use the given base box if given" do + box = "zooo" + Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => box) + @instance.create_vagrantfile(box) + end + + should "use the default `base` if no box is given" do + Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base") + @instance.create_vagrantfile + end + end +end