ruby-changes:33143
From: nobu <ko1@a...>
Date: Sat, 1 Mar 2014 16:08:21 +0900 (JST)
Subject: [ruby-changes:33143] nobu:r45222 (trunk): assertions.rb: assert_all? assert_not_all?
nobu 2014-03-01 16:08:17 +0900 (Sat, 01 Mar 2014) New Revision: 45222 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45222 Log: assertions.rb: assert_all? assert_not_all? * lib/test/unit/assertions.rb (assert_all?, assert_not_all?): new assertions for all iterations. Modified files: trunk/lib/test/unit/assertions.rb Index: lib/test/unit/assertions.rb =================================================================== --- lib/test/unit/assertions.rb (revision 45221) +++ lib/test/unit/assertions.rb (revision 45222) @@ -422,6 +422,26 @@ EOT https://github.com/ruby/ruby/blob/trunk/lib/test/unit/assertions.rb#L422 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)) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/