On Mon, 02 Jun 2003 21:24:00 +0900, John Johnson wrote:

> My Ruby programs seem to be one monolithic source file (~500 lines or so).
> With classes defined, global functions, and, uhm, a global variable or two.
> Problem is, I have functions that do a whole lot. They might open a file or
> two, massage the data, and put it back into another file.

my ruby files is about 250 lines.


> Is it possible to devise unit tests for programs structured like this?

No, you will have to isolate those things you want to do internal testing.
Yes, you can do external testing.


> Should I break my program into more source files?

Yes. 

1) I have a class containing many methods (more than 40).

2) I find out which methods whos related to eachother and move 
   them out from the class into a standalone module.

3) Now you have 10 files and your main class looks like this:
   class Main
       include MainModuleA
       include MainModuleB
       include MainModuleC
   end


Now I want to write unittest for MainModuleA, i do like:
   class FakeMain
       include MainModuleA
       # overload methods that MainModuleA depends on
   end

   class TestBufferVert < RUNIT::TestCase 
       def test_behavier
           i = FakeMain.new
           res = i.dostuff
           assert_equal("42", res)
       end
   end
    

Remember to write unittest before implementation :-)


> Feel free to tell me to RTFM, just provide a link to it :-)

I know no manual I can point you to.. 
maybe read about aspect oriented programming (AOP).


--
Simon Strandgaard