From 3541b903d55d0940df9a133d921f59b6b21c4609 Mon Sep 17 00:00:00 2001 From: John Bender Date: Wed, 28 Jul 2010 22:42:06 -0700 Subject: [PATCH] tests added for warden --- test/vagrant/action/warden_test.rb | 39 +++++++++++++++++++++++++++--- test/vagrant/action_test.rb | 19 --------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/test/vagrant/action/warden_test.rb b/test/vagrant/action/warden_test.rb index 05a4c33f5..c71cd2283 100644 --- a/test/vagrant/action/warden_test.rb +++ b/test/vagrant/action/warden_test.rb @@ -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 diff --git a/test/vagrant/action_test.rb b/test/vagrant/action_test.rb index 3c184d0cb..fe0de9c28 100644 --- a/test/vagrant/action_test.rb +++ b/test/vagrant/action_test.rb @@ -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