tests added for warden

This commit is contained in:
John Bender 2010-07-28 22:42:06 -07:00
parent 36f0eb8feb
commit 3541b903d5
2 changed files with 36 additions and 22 deletions

View File

@ -56,12 +56,37 @@ class ActionWardenTest < Test::Unit::TestCase
end
should "begin rescue on environment error" do
env = new_env
env.error!(:foo)
@instance.expects(:begin_rescue)
@instance.actions << lambda {}
@instance.actions.first.expects(:call).never
@instance.call(env)
@instance.call(new_env_with_error)
end
should "not call the next action on env err" do
action = mock('action')
action.expects(:call).never
@instance.actions << action
@instance.expects(:begin_rescue)
@instance.call(new_env_with_error)
end
should "call begin rescue when the called action returns with an env error" do
class Foo
def initialize(*args); end
def call(env)
return env.error!(:foo)
end
end
@instance.actions << Foo.new
@instance.expects(:begin_rescue)
@instance.call(new_env)
end
def new_env_with_error
env = new_env
env.error!(:foo)
env
end
end
@ -97,8 +122,16 @@ class ActionWardenTest < Test::Unit::TestCase
env.expects(:interrupted?).returns(true)
@instance.begin_rescue(env)
end
context "with many middleware" do
should "not call middleware after" do
end
end
end
def new_env
Vagrant::Action::Environment.new(nil)
end

View File

@ -88,24 +88,5 @@ class ActionTest < Test::Unit::TestCase
@instance.run(callable, :bar => :foo)
end
should "exit if environment was marked as interrupted" do
callable = lambda do |env|
env.error!(:interrupt)
end
@instance.stubs(:error_and_exit)
@instance.expects(:exit).once
@instance.run(callable)
end
should "error and exit if erroneous environment results" do
callable = lambda do |env|
env.error!(:key, :foo => :bar)
end
@instance.expects(:error_and_exit).with(:key, :foo => :bar)
@instance.run(callable)
end
end
end