mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
assertions.rb: allow proc
* lib/test/unit/assertions.rb (assert_raise): allow a proc as message like as other assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c8a7730c7d
commit
d5d8097afd
1 changed files with 30 additions and 2 deletions
|
@ -63,8 +63,36 @@ module Test
|
||||||
# assert_raise NameError do
|
# assert_raise NameError do
|
||||||
# puts x #Raises NameError, so assertion succeeds
|
# puts x #Raises NameError, so assertion succeeds
|
||||||
# end
|
# end
|
||||||
def assert_raise(*args, &b)
|
def assert_raise(*exp, &b)
|
||||||
assert_raises(*args, &b)
|
case exp.last
|
||||||
|
when String, Proc
|
||||||
|
msg = exp.pop
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
yield
|
||||||
|
rescue MiniTest::Skip => e
|
||||||
|
return e if exp.include? MiniTest::Skip
|
||||||
|
raise e
|
||||||
|
rescue Exception => e
|
||||||
|
expected = exp.any? { |ex|
|
||||||
|
if ex.instance_of? Module then
|
||||||
|
e.kind_of? ex
|
||||||
|
else
|
||||||
|
e.instance_of? ex
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
assert expected, proc {
|
||||||
|
exception_details(e, message(msg) {"#{mu_pp(exp)} exception expected, not"}.call)
|
||||||
|
}
|
||||||
|
|
||||||
|
return e
|
||||||
|
end
|
||||||
|
|
||||||
|
exp = exp.first if exp.size == 1
|
||||||
|
|
||||||
|
flunk(message(msg) {"#{mu_pp(exp)} expected but nothing was raised."})
|
||||||
end
|
end
|
||||||
|
|
||||||
# :call-seq:
|
# :call-seq:
|
||||||
|
|
Loading…
Add table
Reference in a new issue