Ron Jeffries <ronjeffries / REMOVEacm.org> writes:

> >However, just to make your like happier, did you know about the
> >'rubyunit' hack?  To write test cases, all you need is

> Where can I find out more about this?

> I'm using Lapidary, is it the official rubyunit release yet (and will it
> be) and does it do that? 

There's a new version of Lapidary called 'testunit' that's made it's
way into the 'rough' CVS tree. testunit is compatible with lapidary
_and_ rubyunit, so it unifies the two testing regimes.

> Last I thought I knew, neither rubyunit nor lapidary had the ability to
> automatically find the testing subclasses and methods, and I have a hack
> of my own that does that, so all my mains are the same.

Seems like a blatant violation of DRY to me, Ron. Not just Hunt and
Thomas, but the spirit of Beck may well descend on you when you least
expect it and deliver a resounding thwack around the head with a three
day old cod.

(Actually it was because of the fact that I that same main program in
all my test code that I wrote the hack. It is distributed with
testunit and with the newer rubyunits. All you have to do is

  require 'rubyunit'

Any class that subclasses TestCase will be considered a class of
tests. There's no need for any main code. If this file is run, it's
tests will be run. If the file is included in another file that is
then run, it's tests will be added to that files tests. You can run
individual methods or classes of methods by specifying their names on
the command line. You can even specify tests to be run using regexps :)

> But it seems that my problem remains ... if I have code in one file
> and tests in another, and I want to initiate testing from whichever
> editing window I'm then in, I seem to need the files to require each
> other ...

OK, how about this:

  code.rb:
     if $0 == __FILE__ 
       require "test.rb"
       exit
     end

     class A
       def return_one
         1
       end
     end

  test.rb:
     require 'rubyunit'
     require 'code'

     class TestCode < TestCase
       def test_return_one
         assert_equals(1, A.new.return_one)
       end
     end


You can run either and it runs the tests. If you include 'code' from
some third source file, it skips them. Was that what you needed?



Dave