1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Multiple exception classes at raise_error

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-05-16 13:51:15 +00:00
parent 8dd82a3e1e
commit 4cfbc59dc3

View file

@ -2,7 +2,7 @@ require 'mspec/utils/deprecate'
class RaiseErrorMatcher class RaiseErrorMatcher
def initialize(exception, message, &block) def initialize(exception, message, &block)
@exception = exception @exception = Array(exception)
@message = message @message = message
@block = block @block = block
end end
@ -19,7 +19,7 @@ class RaiseErrorMatcher
end end
def matching_exception?(exc) def matching_exception?(exc)
return false unless @exception === exc return false unless @exception.any? {|exception_class| exception_class === exc}
if @message then if @message then
case @message case @message
when String when String
@ -36,6 +36,9 @@ class RaiseErrorMatcher
end end
def exception_class_and_message(exception_class, message) def exception_class_and_message(exception_class, message)
if Array === exception_class and exception_class.size == 1
exception_class = exception_class[0]
end
if message if message
"#{exception_class} (#{message})" "#{exception_class} (#{message})"
else else
@ -65,7 +68,7 @@ class RaiseErrorMatcher
def negative_failure_message def negative_failure_message
message = ["Expected to not get #{format_expected_exception}", ""] message = ["Expected to not get #{format_expected_exception}", ""]
unless @actual.class == @exception unless @exception.include?(@actual.class)
message[1] = "but got #{format_exception(@actual)}" message[1] = "but got #{format_exception(@actual)}"
end end
message message