ruby-changes:46639
From: nobu <ko1@a...>
Date: Tue, 16 May 2017 22:57:23 +0900 (JST)
Subject: [ruby-changes:46639] nobu:r58754 (trunk): Use raise_error block
nobu 2017-05-16 22:57:18 +0900 (Tue, 16 May 2017) New Revision: 58754 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58754 Log: Use raise_error block Modified files: trunk/spec/mspec/lib/mspec/matchers/raise_error.rb trunk/spec/rubyspec/library/socket/tcpsocket/shared/new.rb Index: spec/rubyspec/library/socket/tcpsocket/shared/new.rb =================================================================== --- spec/rubyspec/library/socket/tcpsocket/shared/new.rb (revision 58753) +++ spec/rubyspec/library/socket/tcpsocket/shared/new.rb (revision 58754) @@ -9,7 +9,9 @@ describe :tcpsocket_new, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/library/socket/tcpsocket/shared/new.rb#L9 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 Index: spec/mspec/lib/mspec/matchers/raise_error.rb =================================================================== --- spec/mspec/lib/mspec/matchers/raise_error.rb (revision 58753) +++ spec/mspec/lib/mspec/matchers/raise_error.rb (revision 58754) @@ -2,7 +2,7 @@ require 'mspec/utils/deprecate' https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/raise_error.rb#L2 class RaiseErrorMatcher def initialize(exception, message, &block) - @exception = Array(exception) + @exception = exception @message = message @block = block end @@ -19,7 +19,7 @@ class RaiseErrorMatcher https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/raise_error.rb#L19 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 https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/raise_error.rb#L36 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 https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/raise_error.rb#L65 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/