Easy retrieval of actions.
This commit is contained in:
parent
3c943834ea
commit
88587c3322
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue