From: Dave Thomas Date: 2002-02-22T10:13:50+09:00 Subject: Re: recursive require Ron Jeffries writes: > Note that the code classes are defined twice. If I do it the other way > around, running the test file, then it happens the other way around: the > tests are loaded twice and the test files defined twice. > > Either way it's weird. Worst of all, the program runs differently > depending which file I load first. Ron: Ruby won't require or load the same file twice. However, executing the file as a main program doesn't count as loading or requiring it, so: code.rb require "test" puts "code" test.rb require "code" puts "test" When you say 'ruby code.rb', it does require "test" - not yet loaded in test.rb require "code" - not yet loaded (it thinks) in code.rb (again) require "test" - already loaded puts "code" back out to test.rb puts "test" back out to code.rb puts "code" However, just to make your like happier, did you know about the 'rubyunit' hack? To write test cases, all you need is require 'rubyunit' class XX < TestCase def test_xxx end ... end That's it. No suite, and no runner. It finds the test classes and methods automatically. it also composes tests correctly if you require multiple files like the above into another file. _And_ it runs tests by name off the command line if you specify them: ruby my_tests.rb test_xxx Cheers Dave