1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2017-05-24 07:57:18 +00:00
parent d7015ae4ee
commit 73d797ad48

View file

@ -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)) }