[前][次][番号順一覧][スレッド一覧]

ruby-changes:32611

From: nobu <ko1@a...>
Date: Thu, 23 Jan 2014 18:18:51 +0900 (JST)
Subject: [ruby-changes:32611] nobu:r44690 (trunk): assertions.rb: allow proc

nobu	2014-01-23 18:18:47 +0900 (Thu, 23 Jan 2014)

  New Revision: 44690

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44690

  Log:
    assertions.rb: allow proc
    
    * lib/test/unit/assertions.rb (assert_raise): allow a proc as
      message like as other assertions.

  Modified files:
    trunk/lib/test/unit/assertions.rb
Index: lib/test/unit/assertions.rb
===================================================================
--- lib/test/unit/assertions.rb	(revision 44689)
+++ lib/test/unit/assertions.rb	(revision 44690)
@@ -63,8 +63,36 @@ module Test https://github.com/ruby/ruby/blob/trunk/lib/test/unit/assertions.rb#L63
       #    assert_raise NameError do
       #      puts x  #Raises NameError, so assertion succeeds
       #    end
-      def assert_raise(*args, &b)
-        assert_raises(*args, &b)
+      def assert_raise(*exp, &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
 
       # :call-seq:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]