How to… Rails Testing for noobies

Ruby on Rails comes with very nice testing tools. Use them!
In order to get your test working follow the next steps:

  1. First create and set up your testing database, remember that by default you are working under a development environmet so.. if you dont want to lose this configuration, and still test on the same computer you are developing just specify that you will run db:create rake task for test env just like this: $ rake db:create RAILS_ENV=test
  2. After your database is created run all migrations using the same “hack”: $ rake db:migrate RAILS_ENV=test

There are better ways to this, remember this is just a spank on your but to get you started.
For more information refer to this guide by clicking here, there you will find all you need to test like a pro.

I sugest you use the autotest gem to make it easier for you to test, specially on code refactorings.
Install auto test by running:
$ gem install ZenTest
Use it by running:
$ autotest - -rails

Check this site out for a screencast on autotest http://nubyonrails.com/articles/autotest-rails theres also a cool railscast for this topic on railscasts.com look for the 11th one.
Enjoy.
Recommend Me

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: