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:
parent
db17d694ea
commit
0b8233ab07
1 changed files with 20 additions and 0 deletions
|
@ -422,6 +422,26 @@ EOT
|
||||||
alias assert_include assert_includes
|
alias assert_include assert_includes
|
||||||
alias assert_not_include assert_not_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:
|
def build_message(head, template=nil, *arguments) #:nodoc:
|
||||||
template &&= template.chomp
|
template &&= template.chomp
|
||||||
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
|
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
|
||||||
|
|
Loading…
Add table
Reference in a new issue