From: Daniel Berger Date: 2007-02-04T00:50:10+09:00 Subject: Re: Mixing Rake and Turn On Feb 3, 5:40 am, Jan Friedrich wrote: > Daniel Berger wrote: > > Upon further review, using TestTask#ruby_opts *does* work. The bug was > > mine. > > > Anyhoo, for the sake of future Googlers, this is how you do it: > > > desc "Runs the test suite for the Foo class" > > Rake::TestTask.new('test_foo') do |t| > > t.test_files = FileList['test/foo/*.rb'] # Or whatever > > t.ruby_opts << '-rturn' > > t.warning = true > > end > > But you have now a dependency to turn. If you share your program with > others they have to install turn if they want to use the test task. :( > > I prefer at the moment the following snipped on top of every test file: > > require 'test/unit' > begin > require 'turn' > rescue LoadError; end > > So you can running tests with or without turn installed. > > Other ideas? In one project I have way too many files for that to be feasible. A simpler approach would be to do this at the top of the Rakefile: $turn = true begin require 'turn' rescue LoadError $turn = false end t.ruby_opts << '-rturn' if $turn The only problem with that is that, as Tim mentioned earlier, you'll get the bogus "zero" test results at the end (in addition to the real results). To avoid that, we could check to see if the turn.rb file merely exists instead of actually loading it: require 'rbconfig' include Config $turn = false $turn = true if File.exists?(File.join(CONFIG['sitelibdir'], 'turn.rb')) t.ruby_opts << '-rturn' if $turn This is what I plan on doing. Regards, Dan