summaryrefslogtreecommitdiff
path: root/test/lib/test/unit
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-24 07:57:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-24 07:57:18 +0000
commit73d797ad48bfe73d63d7666fc9fd46fda5031dfe (patch)
tree4ee7655c94c1c27735a0a77593ba6918cfbc13bc /test/lib/test/unit
parentd7015ae4ee916c8468aa816b8b188ad44e0b4545 (diff)
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
Diffstat (limited to 'test/lib/test/unit')
-rw-r--r--test/lib/test/unit/assertions.rb19
1 files changed, 19 insertions, 0 deletions
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)) }