From: Jean-Hugues ROBERT Date: 2002-05-24T05:51:00+09:00 Subject: Re: [RDoc etc] automatic documentation: using tests in addition to / instead of comments Hello, At 03:56 24/05/2002 +0900, you wrote: >Here are my two cents. > >I usually put each major class in its own file together with its >tests. The interpreter only sees the tests if the file to be run is >the one that contains them, not if the file was required in another >file. I like that. What happens if code is "loaded" instead of "required" ? >I do it this way because this allows to iteratively run and develop >the class being working on. From Emacs it goes like: write test, run >with C-c s, see test results, modify class, run, and so on. No >loading or saving involved, speed goes up. I do differently. I do C-c C-s once for all. Then I do C-c C-l to load the file. This way I save the time it takes to start IRB, stop it and close the *ruby* buffer. Occasionnaly I have to to C-c C-s again, specially when some constants need to be cleared, but I avoid it most of the time. >It looks like this: >class Foo > def bar > ... > end >end >if $0 == __FILE__ > require 'test/unit' > class TestFoo < Test::Unit::TestCase > def test_bar > ... > end > end >end >With `ruby foo.rb' on the command line, test will be run. With >`require "foo.rb"' in some other file, they won't even be defined. Is there a way a source file can detect that it was "required" versus it was "loaded" ? Hacks welcomed too. Yours, Jean-Hugues ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17