Writing a Ruby Test Suite that RDT and Test::Unit Can Understand
Posted: September 20th, 2005 Tags: Howto, Ruby on RailsI’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
November 17th, 2005 at 8:38 am
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!