Test::Unit assert_throws

Discussion in 'Ruby' started by asplake, Jan 1, 2006.

  1. asplake

    asplake Guest

    Hi,

    Any good examples out there (I couldn't find any) of assert_throws? I
    would love to know also why its first argument is a symbol...

    Thanks
    Mike
     
    asplake, Jan 1, 2006
    #1
    1. Advertising

  2. asplake

    George Ogata Guest

    "asplake" <> writes:

    > Hi,
    >
    > Any good examples out there (I couldn't find any) of assert_throws? I
    > would love to know also why its first argument is a symbol...


    #assert_throw checks for a Kernel#throw, which takes a Symbol.
    Perhaps you were after #assert_raise ?

    --------------------

    require 'test/unit'

    def f
    throw :x
    end

    def g
    raise
    end

    class T < Test::Unit::TestCase
    def test_a
    assert_throws:)x){f} # pass
    assert_throws:)y){f} # fail
    end
    def test_b
    assert_raise(RuntimeError ){g} # pass
    assert_raise(ArgumentError){g} # fail
    end
    end
     
    George Ogata, Jan 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VvanN
    Replies:
    5
    Views:
    515
    Phlip
    Apr 28, 2006
  2. Bill David
    Replies:
    2
    Views:
    284
    Arne Vajhøj
    Jun 18, 2008
  3. Peter Fitzgibbons

    Assert_throws

    Peter Fitzgibbons, Sep 12, 2005, in forum: Ruby
    Replies:
    2
    Views:
    144
    James Edward Gray II
    Sep 12, 2005
  4. Intransition

    minitest assert_throws, why rescue?

    Intransition, Sep 2, 2009, in forum: Ruby
    Replies:
    2
    Views:
    148
    trans
    Sep 2, 2009
  5. timr
    Replies:
    2
    Views:
    180
Loading...

Share This Page