Thursday, September 10, 2009
Rspec and Test::Unit
This post is not intended to discuss which of the two testing frameworks is best. We have use both of them in many applications and we would like to share some of our experiences.
RSpec has lots of English-like syntax making our specs look sexy. It leads us to write things like: user.should have(1).error_on(:password). This is sufficiently explicit even for non-programmers people. The expressiveness introduced by RSpec help us to compare our client requirements with the specifications we write in order to complete the TDD cycle.
On the other hand we have Test::Unit. A simpler and powerful testing framework where practically all of our tests are reduced to assertions. It makes assert user.errors.on(:password) no more expressive than user.should have(n).errors_on(:password), but is still explicit enough and simple to understand.
Most of time you’ll be writing longer and expressive specifications with RSpec than Test::Unit, so it’s up to you decide which one to use. Pick one that fits your personal preference and feel more comfortable. Both are just as flexible and capable of testing your code. The main difference is the way in which you write tests.
Lately, many people are moving from Test::Unit to RSpec. RSpec is an awesome framework, but Test::Unit simplicity would make testing things easier in most situations so it’s an option you should consider when deciding what testing framework to use.