Retryable can take multiple exceptions to retry on

This commit is contained in:
Mitchell Hashimoto 2011-04-19 22:24:52 -07:00
parent 0953c41446
commit 234c47a3a7
2 changed files with 13 additions and 1 deletions

View File

@ -12,7 +12,7 @@ module Vagrant
begin
return yield
rescue opts[:on]
rescue *opts[:on]
if (opts[:tries] -= 1) > 0
sleep opts[:sleep].to_f if opts[:sleep]
retry

View File

@ -31,6 +31,18 @@ class RetryableUtilTest < Test::Unit::TestCase
}
end
should "retry on multiple exceptions given" do
proc = mock("proc")
proc.expects(:call).twice
assert_raises(StandardError) {
@klass.retryable(:tries => 2, :on => [StandardError, RuntimeError]) do
proc.call
raise StandardError
end
}
end
should "return the value of the block" do
result = @klass.retryable { 7 }
assert_equal 7, result