From: Ron Jeffries Date: 2002-02-22T19:19:46+09:00 Subject: Re: recursive require I'm reordering Patrick's comments so that my answers flow better ... On 21 Feb 2002 17:58:56 -0800, patrick-may@monmouth.com (Patrick May) wrote: >Also, why are you seperating the tests from the code? it makes more >sense to me for a test and its class to be in the same file, instead >of multiple classes and multiple tests in seperate files. Well, I just did it because (a) the file got large with both tests and code in it, a couple of hundred lines each so far and (b) it seemed like in real use I wouldn't want 200 lines of tests compiling every time I used this object. >What seems smelly to me is that you have two points of entry to the >same application(the tests): the code file, and the test file. Yes. That's because in TextPad, my current editor of choice, I want to just press control-3 and run, no matter what window I'm currently editing. So I need the same main in each program. My basic convention is that a naked run runs the tests, a run with parameters runs the code. >If anything, you are violating DRY b/c you've got the same bootstrap >code in both files... Yes. Of course most of us have almost exacly the same main program in every Ruby file we write. So I'm not deeply concerned about this, though Andy and Dave may descend upon me like locusts when they find out. >Maybe you could... > >? have one point of entry: either the code file, the tests file, or a >third "runner" file > >? have each file do different things: code file runs the code, test >file runs the test Because of the way TextPad works, or my limitations in setting up TextPad tools, I can't work the way I want to unless I do this. I want to just press the test button any time and go. I just thought of one way I could do it, but it would be a reach from where I am now ... I could write a generic testrunner program that when it starts it just required in all the files in the working directory and then dynamiically ran all the tests that were defined ... It would be like the loading test runner in Java. How does that one know what to load? >> I'm having a really odd thing happen with two files that mutually >> require each other, and I'm hoping for help. I think an interesting point here is that whenever two files mutually require the other, the classes are defined twice in one of them (whichever one you load first. That seems like a bug to me. Should I produce a simple bug report? I'll wager I can write one such that class Foo @@foo = 0 @@foo += 1 end will wind up with @@foo = 1 if you start from one file, and 2 if you start from the other. That is at least odd, if not dead wrong. Or so it seems to me ... Thanks, Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.