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

assertions.rb: assert_all? assert_not_all?

* lib/test/unit/assertions.rb (assert_all?, assert_not_all?): new
  assertions for all iterations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-03-01 07:08:17 +00:00
parent db17d694ea
commit 0b8233ab07

View file

@ -422,6 +422,26 @@ EOT
alias assert_include assert_includes
alias assert_not_include assert_not_includes
def assert_all?(obj, m = nil, &blk)
failed = []
obj.each do |*a, &b|
unless blk.call(*a, &b)
failed << (a.size > 1 ? a : a[0])
end
end
assert(failed.empty?, message(m) {failed.pretty_inspect})
end
def assert_not_all?(obj, m = nil, &blk)
failed = []
obj.each do |*a, &b|
if blk.call(*a, &b)
failed << a.size > 1 ? a : a[0]
end
end
assert(failed.empty?, message(m) {failed.pretty_inspect})
end
def build_message(head, template=nil, *arguments) #:nodoc:
template &&= template.chomp
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }