Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why does running a Test::unit test in irb work so weirdly?

Reply
Thread Tools

Why does running a Test::unit test in irb work so weirdly?

 
 
Peter Recore
Guest
Posts: n/a
 
      02-16-2008
Why can't I run a Test::Unit::TestCase from IRB and have it run before I
quit?
I have found this problem mentioned by others. For an example, see this
tutorial about testing:

http://www.nullislove.com/2007/11/14...sting-in-ruby/

>irb --simple-prompt
>> require 'test/unit'

=> true
>> class FirstTests < Test::Unit::TestCase
>> def test_addition
>> assert(1 + 1 == 2)
>> end
>>
>> def test_subtraction
>> assert(1 - 1 == 2)
>> end
>> end

=> nil
>> quit

Loaded suite irb
Started
F
Finished in 0.00119 seconds.

The author mentions that a quirk of irb makes this happen but doesn't
say what the quirk is:

"When we finished the definition, nothing happened. When we exited IRB,
then our tests ran. That’s a characteristic of using IRB for our tests
and won’t be significant as we move on."

Thanks for any insight you have.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Christopher Dicely
Guest
Posts: n/a
 
      02-16-2008
On Feb 16, 2008 11:35 AM, Peter Recore <> wrote:
> Why can't I run a Test::Unit::TestCase from IRB and have it run before I
> quit?


You can, you just have to explicitly tell it to run. Normally, you
don't explicitly run Test::Unit tests, you simply define them and then
they run automagically when ruby exits, because the Test::Unit
library, when it is loaded, loads an at_exit routine that will (unless
something has told it not too) run the tests that have been defined.
Its not really an IRB quirk that stops them from running until you
exit, its just that when you run a script with unit tests
"standalone", you don't realize that the tests are run when it is
exiting. With IRB, you just notice what is going on regularly when you
use Test::Unit.

The RDoc for Test::Unit gives this example of how to explicitly run a test case:

require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TC_MyTest)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
irb require ... where does irb look? what path? anne001 Ruby 1 06-27-2006 12:07 PM
irb question - variable definitions when calling irb from a script problem Nuralanur@aol.com Ruby 1 10-26-2005 09:13 PM
[ANN] irb-history 1.0.0: Persistent, shared Readline history for IRB Sam Stephenson Ruby 1 06-18-2005 08:56 AM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57