Ruby Test Runner

29 Jun 2009

For my Peddinghaus IDE application, I wanted to practice TDD. Ruby has a great built in unit testing framework (the unit testing framework that Rails uses extensively). Ruby also has some great plugins for testing. For Peddinghaus, I am using Cucumber and RSpec. These two plugins, along with Test::Unit are the basis for my testing stack (more information on this stack later). However, I really didnít have a way to run these tests effectively. So, I set out to create my own Ruby Test Runner.

Rails is synonymous with Ruby in most peopleís eyes. However, Ruby is a powerful language in itself that has an ever-growing library of tools and plugins that is going to make it a first-class language in the near future. My project is a desktop environment application and thus isnít a Rails app. This means that I donít get some of the built-in test runners that are in Rails.

So, you can either run the tests module by module, testing framework by testing framework, or you can create a script. Some people would prefer to make a sh script that can run in their particular environment. This is fine, but I wanted to see if I couldnít hook directly into the APIs of each framework. Getting into the Test::Unit framework was pretty easy and straightforward while hooking into the two plugins was more difficult. In the end for that, I had to settle for a work-around. Code follows:

I decided to break it up because I wanted to be able to separate the UI and the logic. This is a very simple case that will likely never be changed, but I may be motivated enough to write a GUI for the test runner that replaces (or supplements) the command like test runner. Or, I could change the business layer and never worry about UI layer changes. I think its more clean this way.

(Note: I realize that there are some bad variable names and inconsistencies [notably a and the long form of the arguments for the test runner] but they will be fixed before it goes into source control.)

As you may see, the workaround for Cucumber and RSpec is to just call the commands themselves. However, Iím sure that there is a way to hook into these testing frameworks and create your own runner (and, if not, that should definitely be added). I could imagine that if I were to put a real team on this project and would want some real results, Iíd have someone put some time into an integrated test runner GUI with an integration server test runner counterpart. For now, the above solution should suffice.

If anyone has information on the Cucumber and RSpec runners, please let me know!