Manipulate output from test/unit methods?

Discussion in 'Ruby' started by Chris McMahon, Oct 6, 2005.

  1. When you use any of the test/unit methods, like "assert_equal", you
    always get a nice output message like

    1 tests, 2 assertions, 0 failures, 0 errors

    or

    <"CLARICE"> expected but was
    <"JOHN">.
    1 tests, 1 assertions, 1 failures, 0 errors

    How can I manipulate that output message, for instance assign the whole
    string from "<"CLARICE"> to "0 errors" to a variable?

    It's not in $_ or $! or $stdout or $stdout, and I can't seem to assign
    it to a variable. None of these work; the puts's are always "nil" or
    something obscure from IO#:

    a = assert_equal(x,y)
    puts a

    assert_equal(x,y)
    puts $_

    assert_equal(x,y)
    puts $!

    puts $stdout
    puts $stdout
     
    Chris McMahon, Oct 6, 2005
    #1
    1. Advertising

  2. Chris McMahon

    Eric Hodel Guest

    On Oct 6, 2005, at 11:56 AM, Chris McMahon wrote:

    > When you use any of the test/unit methods, like "assert_equal", you
    > always get a nice output message like
    >
    > 1 tests, 2 assertions, 0 failures, 0 errors
    >
    > or
    >
    > <"CLARICE"> expected but was
    > <"JOHN">.
    > 1 tests, 1 assertions, 1 failures, 0 errors
    >
    > How can I manipulate that output message, for instance assign the
    > whole
    > string from "<"CLARICE"> to "0 errors" to a variable?


    Well... What are you trying to accomplish? ZenTest's unit_diff works
    with output messages as a filter, so you just have to pipe your test/
    unit output through it.

    --
    Eric Hodel - - http://segment7.net
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
     
    Eric Hodel, Oct 7, 2005
    #2
    1. Advertising

  3. Chris McMahon

    Damphyr Guest

    Eric Hodel wrote:
    > On Oct 6, 2005, at 11:56 AM, Chris McMahon wrote:
    >
    >> When you use any of the test/unit methods, like "assert_equal", you
    >> always get a nice output message like
    >>
    >> 1 tests, 2 assertions, 0 failures, 0 errors

    ---
    >
    > Well... What are you trying to accomplish? ZenTest's unit_diff works
    > with output messages as a filter, so you just have to pipe your
    > test/ unit output through it.
    >

    Well this is a related question on the output of unit tests:
    Is there a way to suppress everything except the result of the tests?
    I have lots of negative tests (where the error handling of my apps is
    checked) and would like to shut off the exceptions and their messages on
    a succesful negative test (this makes the logs of automated test runs a
    lot lighter).
    Cheers,
    V.-

    --
    http://www.braveworld.net/riva

    ____________________________________________________________________
    http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
    http://www.freemail.gr - free email service for the Greek-speaking.
     
    Damphyr, Oct 7, 2005
    #3
    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. Dave
    Replies:
    1
    Views:
    331
    Mike Wahler
    Jan 22, 2005
  2. VvanN
    Replies:
    5
    Views:
    489
    Phlip
    Apr 28, 2006
  3. Bill David
    Replies:
    2
    Views:
    273
    Arne Vajhøj
    Jun 18, 2008
  4. Bill Mosteller
    Replies:
    0
    Views:
    230
    Bill Mosteller
    Oct 22, 2009
  5. timr
    Replies:
    2
    Views:
    167
Loading...

Share This Page