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

ruby-changes:30881

From: nobu <ko1@a...>
Date: Tue, 17 Sep 2013 15:53:25 +0900 (JST)
Subject: [ruby-changes:30881] nobu:r42960 (trunk): assertions.rb: assert_throw

nobu	2013-09-17 15:53:21 +0900 (Tue, 17 Sep 2013)

  New Revision: 42960

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

  Log:
    assertions.rb: assert_throw
    
    * lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_throw):
      assertion for throw.  MiniTest::Assertions#assert_throws discards
      the cautht value.

  Modified files:
    trunk/ChangeLog
    trunk/lib/test/unit/assertions.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42959)
+++ ChangeLog	(revision 42960)
@@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Tue Sep 17 15:52:32 2013  Nobuyoshi Nakada  <nobu@r...>
+Tue Sep 17 15:53:20 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_throw):
+	  assertion for throw.  MiniTest::Assertions#assert_throws discards
+	  the cautht value.
 
 	* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_nothing_thrown):
 	  returns the result of the given block.
Index: lib/test/unit/assertions.rb
===================================================================
--- lib/test/unit/assertions.rb	(revision 42959)
+++ lib/test/unit/assertions.rb	(revision 42960)
@@ -170,6 +170,25 @@ module Test https://github.com/ruby/ruby/blob/trunk/lib/test/unit/assertions.rb#L170
       end
 
       # :call-seq:
+      #   assert_throw( tag, failure_message = nil, &block )
+      #
+      #Fails unless the given block throws +tag+, returns the caught
+      #value otherwise.
+      #
+      #An optional failure message may be provided as the final argument.
+      #
+      #    tag = Object.new
+      #    assert_throw(tag, "#{tag} was not thrown!") do
+      #      throw tag
+      #    end
+      def assert_throw(tag, msg = nil)
+        catch(tag) do
+          yield(tag)
+          assert(false, message(msg) {"Expected #{mu_pp(tag)} to have been thrown"})
+        end
+      end
+
+      # :call-seq:
       #   assert_equal( expected, actual, failure_message = nil )
       #
       #Tests if +expected+ is equal to +actual+.

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

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