Erik A. Hanson's Weblog

Writing a Ruby Test Suite that RDT and Test::Unit Can Understand

Posted: September 20th, 2005    Tags: Howto, Ruby on Rails

I’m working on a Ruby project using Eclipse and RDT. RDT provides a couple useful features, including support for running unit tests with Test::Unit. Unfortunately, it’s pretty primitive at the moment.

One big problem is that it can’t run all your tests. So we wrote a test suite class that runs all tests and can be run from Test::Unit:

require 'test/unit'

Dir.chdir("test")
@@test_files = Dir.glob("**/*_test.rb")
@@test_files.each {|x| require x} 

class TestSuite
  def self.suite
    suite = Test::Unit::TestSuite.new

    @@test_files.each do |filename|
      File.open(filename) do |file|
        file.each_line do |line|
          if match = (/class\s+(\w+Test)/).match(line)
           suite << eval(match[1] + ".suite")
          end
        end
      end
    end

    return suite

  end
end


One Response to “Writing a Ruby Test Suite that RDT and Test::Unit Can Understand”

  1. Rich J. Says:

    Thank you very much Erik. That worked. I was having a problem running my ruby unit tests inside the RDT Eclipse plug-in even though the tests worked fine in the xterm. (Fedora Core 4). I’m glad I found this site!

Leave a Reply



(Comments are moderated to keep out spam. Please be patient.)