From 0b8233ab07a9bfc2c100f395031adfef23c8b491 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 1 Mar 2014 07:08:17 +0000 Subject: 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 --- lib/test/unit/assertions.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/test') 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)) } -- cgit v1.2.3