diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index 98d01df754..869baf505f 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -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)) }