From 2aae783fce172e80d14c22a4f4ea07542dd35380 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 24 May 2017 07:57:18 +0000 Subject: assertions.rb: AllFailures#foreach * test/lib/test/unit/assertions.rb (AllFailures#foreach): shortcircuit for `each` and `AllFailures#for`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/lib/test/unit/assertions.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/lib') diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index 4b331da33d..976a6fd04a 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -835,6 +835,17 @@ eom @failures[key] = [@count, e] end + def foreach(*keys) + keys.each do |key| + @count += 1 + begin + yield key + rescue Exception => e + @failures[key] = [@count, e] + end + end + end + def message i = 0 total = @count.to_s @@ -857,6 +868,14 @@ eom end alias all_assertions assert_all_assertions + def assert_all_assertions_foreach(msg = nil, *keys, &block) + all = AllFailures.new + all.foreach(*keys, &block) + ensure + assert(all.pass?, message(msg) {all.message.chomp(".")}) + end + alias all_assertions_foreach assert_all_assertions_foreach + def build_message(head, template=nil, *arguments) #:nodoc: template &&= template.chomp template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) } -- cgit v1.2.3