зеркало из https://github.com/github/ruby.git
Use raise_error block
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
9bb63a50f5
Коммит
ff88c2a9d3
|
@ -2,7 +2,7 @@ require 'mspec/utils/deprecate'
|
|||
|
||||
class RaiseErrorMatcher
|
||||
def initialize(exception, message, &block)
|
||||
@exception = Array(exception)
|
||||
@exception = exception
|
||||
@message = message
|
||||
@block = block
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ class RaiseErrorMatcher
|
|||
end
|
||||
|
||||
def matching_exception?(exc)
|
||||
return false unless @exception.any? {|exception_class| exception_class === exc}
|
||||
return false unless @exception === exc
|
||||
if @message then
|
||||
case @message
|
||||
when String
|
||||
|
@ -36,9 +36,6 @@ class RaiseErrorMatcher
|
|||
end
|
||||
|
||||
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
|
||||
"#{exception_class} (#{message})"
|
||||
else
|
||||
|
@ -68,7 +65,7 @@ class RaiseErrorMatcher
|
|||
|
||||
def negative_failure_message
|
||||
message = ["Expected to not get #{format_expected_exception}", ""]
|
||||
unless @exception.include?(@actual.class)
|
||||
unless @actual.class == @exception
|
||||
message[1] = "but got #{format_exception(@actual)}"
|
||||
end
|
||||
message
|
||||
|
|
|
@ -9,7 +9,9 @@ describe :tcpsocket_new, shared: true do
|
|||
it "refuses the connection when there is no server to connect to" do
|
||||
lambda do
|
||||
TCPSocket.send(@method, SocketSpecs.hostname, SocketSpecs.reserved_unused_port)
|
||||
end.should raise_error([Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL])
|
||||
end.should raise_error(SystemCallError) {|e|
|
||||
[Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL].should include(e.class)
|
||||
}
|
||||
end
|
||||
|
||||
describe "with a running server" do
|
||||
|
|
Загрузка…
Ссылка в новой задаче