Run "environment_load" action on environment load

This commit is contained in:
Mitchell Hashimoto 2010-09-06 23:36:48 -07:00
parent 1a5836ee23
commit 1478818939
3 changed files with 18 additions and 16 deletions

View File

@ -117,6 +117,12 @@ module Vagrant
end
register :box_repackage, box_repackage
# post_load - Called after environment is loaded
environment_load = Builder.new do
end
register :environment_load, environment_load
end
end
end

View File

@ -210,6 +210,7 @@ module Vagrant
self.class.check_virtualbox!
load_config!
load_vm!
actions.run(:environment_load)
self
end

View File

@ -165,30 +165,24 @@ class EnvironmentTest < Test::Unit::TestCase
end
context "accessing host" do
setup do
@env = vagrant_env
end
should "load the host once" do
env = @klass.new(:cwd => vagrant_app)
result = mock("result")
Vagrant::Hosts::Base.expects(:load).with(@env, @env.config.vagrant.host).once.returns(result)
assert_equal result, @env.host
assert_equal result, @env.host
assert_equal result, @env.host
Vagrant::Hosts::Base.expects(:load).with(env, env.config.vagrant.host).once.returns(result)
assert_equal result, env.host
assert_equal result, env.host
assert_equal result, env.host
end
end
context "accessing actions" do
setup do
@env = vagrant_env
end
should "initialize the Action object with the given environment" do
env = @klass.new(:cwd => vagrant_app)
result = mock("result")
Vagrant::Action.expects(:new).with(@env).returns(result).once
assert_equal result, @env.actions
assert_equal result, @env.actions
assert_equal result, @env.actions
Vagrant::Action.expects(:new).with(env).returns(result).once
assert_equal result, env.actions
assert_equal result, env.actions
assert_equal result, env.actions
end
end
@ -328,6 +322,7 @@ class EnvironmentTest < Test::Unit::TestCase
@klass.expects(:check_virtualbox!).once.in_sequence(call_seq)
@env.expects(:load_config!).once.in_sequence(call_seq)
@env.expects(:load_vm!).once.in_sequence(call_seq)
@env.actions.expects(:run).with(:environment_load).once.in_sequence(call_seq)
assert_equal @env, @env.load!
end
end