Easy retrieval of actions.

This commit is contained in:
Mitchell Hashimoto 2010-07-06 20:16:01 -07:00
parent 3c943834ea
commit 88587c3322
3 changed files with 26 additions and 2 deletions

View File

@ -19,6 +19,11 @@ module Vagrant
def register(key, callable)
actions[key] = callable
end
# Retrieves a registered action by key.
def [](key)
actions[key]
end
end
# The environment to run the actions in.

View File

@ -144,6 +144,10 @@ class ActionBuilderTest < Test::Unit::TestCase
end
context "converting to an app" do
teardown do
Vagrant::Action.actions.clear
end
should "preprend error halt to the chain" do
result = mock("result")
env = {:a => :b}
@ -170,8 +174,6 @@ class ActionBuilderTest < Test::Unit::TestCase
@instance.to_app(nil)
}
end
# TODO: Better testing of this method
end
context "calling" do

View File

@ -5,6 +5,23 @@ class ActionTest < Test::Unit::TestCase
@klass = Vagrant::Action
end
context "with a class" do
teardown do
@klass.actions.clear
end
should "be able to register an action" do
@klass.register(:foo, :bar)
assert @klass.actions.has_key?(:foo)
assert_equal :bar, @klass.actions[:foo]
end
should "be able to retrieve an action using []" do
@klass.register(:foo, :bar)
assert_equal :bar, @klass[:foo]
end
end
context "with an instance" do
setup do
@instance = @klass.new(mock_environment)