diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-01 07:08:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-01 07:08:17 +0000 |
commit | 0b8233ab07a9bfc2c100f395031adfef23c8b491 (patch) | |
tree | 9cd0bf0784a02b15fafabfe99aa3f8490db4bdfe | |
parent | db17d694ea6849b813a09856008310168c5a04ea (diff) | |
download | ruby-0b8233ab07a9bfc2c100f395031adfef23c8b491.tar.gz |
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
-rw-r--r-- | lib/test/unit/assertions.rb | 20 |
1 files changed, 20 insertions, 0 deletions
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)) } |