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

About Me

I'm a software developer and consultant in San Francisco. I mostly develop web apps in Javascript, Java and Rails. There's a little more about me on my LinkedIn profile.

Recent Projects

wshlst.com: a group-oriented wish list website.

BoardsConsult​/​RotationTracker: a site to help medical residents prepare for the U.S. Medical Licensing Exam, and a related site to help medical schools evaluate and track the progress of the residents in their programs.

Jobs

I moderate a few completely free jobs mailing lists with RSS feeds and zero spam: XP jobs, Rails jobs and Mac development jobs. Also, my pals at Pivotal Labs have agile Rails and Java job openings.

Plug: Web Hosting

Looking for cheap shared web hosting and/or domain registration? I've been using DreamHost for years and I've been very happy with them. They offer tons of disk space and bandwidth, one-click installation for apps like WordPress and Gallery, unlimited domains, thousands of email accounts, private domain registration, and more. They are also a nice bunch of folks, not some big dumb company.