cheat sheets.

$ cheat test_unit
Ruby - Test::Unit
===============================================================================
Basic Usage:

    require 'test/unit'

    class Test_SomethingToTest < Test::Unit::TestCase
      def setup
        #will be run prior to each test
      end

      # Replace this with your real tests.
      def test_truth
        assert true
      end
    end


Assertions:
===============================================================================
All assertions also take an optional argument of failure message.

> assert(boolean,[msg])	                
  Ensures that the object/expression is true.

> assert_block([msg]) { block }
  Most basic assertion

> assert_equal(obj1, obj2, [msg])
  Ensures that obj1 == obj2 is true.

> assert_in_delta(expecting, actual, delta, [msg])
  Ensures that the numbers expecting and actual are within delta of each other.
                                                    
> assert_instance_of(class, obj, [msg])
  Ensures that obj is of the class type.

> assert_kind_of(class, obj, [msg])
  Ensures that obj is or descends from class.

> assert_match(regexp, string, [msg])
  Ensures that a string matches the regular expression.

> assert_nil(obj, [msg])
  Ensures that obj.nil? is true.

> assert_no_match(regexp, string, [msg])
  Ensures that a string doesn’t matches the regular expression.
                                          
> assert_not_equal(obj1, obj2, [msg])	  
  Ensures that obj1 == obj2 is false.

> assert_not_nil(obj, [msg])
  Ensures that obj.nil? is false.

> assert_not_same((obj1, obj2, [msg])
  Ensures that obj1.equal?(obj2) is false.

> assert_nothing_raised(exception1, ...) { block }
  Ensures that the given block doesn’t raise one of the given exceptions.
                                                             
> assert_nothing_thrown([msg]) { block }
  Passes if block does not throw anything                      

> assert_operator(obj1, operator, obj2, [msg])
  Ensures that obj1.operator(obj2) is true.

> assert_raise(except1, except2, ...)  { block }
  Ensures that the given block raises one of the given exceptions.

> assert_respond_to(obj, symbol, [msg])
  Ensures that obj has a method called symbol.

> assert_same(obj1, obj2, [msg])
  Ensures that obj1.equal?(obj2) is true.
                                                        
> assert_send(array, [msg])
  Ensures that executing the method listed in array[1] on the object in
  array[0] with the parameters of array[2 and up] is true. This one is weird eh?

> assert_throws(symbol, [msg]) { block }
  Ensures that the given block throws the symbol.
                                          
> flunk([msg])
  Ensures failure. This is useful to explicitly mark a test that isn’t 
  finished yet.

===============================================================================
Updated by: Adam G.
Updated at: 2010-04-22
Version 4, updated 761 days ago.
. o 0 ( | previous | history | revert to | current | diff )
( add new | see all )