Why does running a Test::unit test in irb work so weirdly?
Why can't I run a Test::Unit::TestCase from IRB and have it run before I
I have found this problem mentioned by others. For an example, see this
tutorial about testing:
>> require 'test/unit'
>> class FirstTests < Test::Unit::TestCase
>> def test_addition
>> assert(1 + 1 == 2)
>> def test_subtraction
>> assert(1 - 1 == 2)
Loaded suite irb
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/.
Re: Why does running a Test::unit test in irb work so weirdly?
On Feb 16, 2008 11:35 AM, Peter Recore <email@example.com> wrote:
> Why can't I run a Test::Unit::TestCase from IRB and have it run before I
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
The RDoc for Test::Unit gives this example of how to explicitly run a test case:
|All times are GMT. The time now is 02:27 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.