Rspec vs. TestUnit Rspec vs. TestUnit ruby ruby

Rspec vs. TestUnit


Both Test::Unit and Rspec are very nice solutions. As for me I prefer to use RSpec in my Rails project - because it has many automatic solutions like autotest, highlighting syntax, shortcut commands like rake spec and other stuff that make using test easer. But in my plain ruby scripts I use Test::Unit - it is very lightweight and staightforward when you don't need complex testing (integrational and others)


The answer is matter of taste, use both in one project and find yourself what do you prefer. (I do Test::Unit, RSpec has to much sugar for me).

Update 2014: As Ruby 2.x has MiniTest built-in I would suggest to check MiniTest::Spec eventually which is simple BDD extension. You can mix "describe" and "it" blocks to nicely structure test contexts with. It also provides "must_be.." matchers if you want to more than assert.


I prefer and use these gems for testing

  • Rspec
  • Faker (for creating random and proper data for database)
  • Fabrication (for simple creating instances)

To start with rspec take a look at this presentation. It contains all the necessary examples:

http://kerryb.github.com/iprug-rspec-presentation

Also read through these articles on rspec:

http://relishapp.com/rspec/rspec-rails