Index of All Lessons

Transcript

Download

Play


Support the Course

There’s no charge for the course, but we greatly appreciate any donations.

Suggested donations:

  • One or two lessons: $5
  • Several lessons $10
  • Entire course: $25 – $50

We hope you’ve found the course to be valuable, and we appreciate any support you care to provide.


Sign Up Now!

If you aren’t already receiving our course lessons via email, sign up now to be sure you don’t miss anything.

Every few days, we’ll send you an email with a link to the next episode, plus a list of additional resources for advancing your knowledge.

There’s no cost and no obligation. And we’ll never share your email address with any third party.


We’ll send you the first lesson right away.


Want to help spread the word? We’d be grateful if you would include a link to the course in your blog, web site, or emails.

Testing Rails Code

6 comments

To listen to the lesson, click the Play button on the left. You can also right-click on the download link to save the mp3 file, or you can subscribe in iTunes (just search for Learning Rails).

To read a transcript of the lesson, click the Transcript link on the left.

The heart of the lesson is the audio; these notes are supplementary. So please listen to the audio, or read the transcript, before making use of these notes.

Code Examples

Here’s an example of using asserts. Suppose you have a test that searches for a non-existent podcast episode; you’d want to assert that the result was nil. The test case code would read:

def test_podcast_does_not_exist
  podcast = Podcast.find_by_title('Intro')
  assert_nil podcast
end

Another example checking to see if the test database contains three podcasts loaded from fixtures might read:

def test_three_podcasts_exist
  assert_equal, Podcast.find(:all), 3
end

Here’s an example of a fixture, illustrating how fixtures can use model associations. An entry in the podcast.yml file might read:

episodeone:
  name: Introductory Podcast
  listeners: anne, bob, charlie

and entries in the listeners.yml file would read:

anne:
  name: Anne
  podcast: episodeone

bob:
  name: Bob 
  podcast: episodeone

charlie:
  name: Charlie
  podcast: episodeone

Links to More Resources

See the following sections of the site for links to resources on testing:


Add a Comment

Have a comment or question about this lesson? Add it here.






Comments on This Lesson

From: cherrian chin harada       Date: 10/08/08 03:03 AM

Subject: Testing?

Since I am total beginner on the subject of RoR, this question might sound stupid. Anywhere, goes… Do you immediately start testing after installing RoR? Will RoR affect any of my normal fuctions such as my daily e-mail, word processing functions,etc…?

From: Vitaliy Khudenko       Date: 09/10/08 08:08 AM

Subject: comments count issue

I’ve noticed when I post a comment to a lesson the comments count remains unchanged unless the page is manually reloaded.

From: Vitaliy Khudenko       Date: 09/10/08 08:08 AM

Subject: typo

The example checking to see if the test database contains three podcasts loaded from fixtures is missing size method and actually should be as:

def test_three_podcasts_exist assert_equal, Podcast.find(:all).size, 3 end

From: ChanHan Hy       Date: 08/18/08 04:04 AM

Subject: Good sites resource on testing

It’s important. Great Resources.

From: Juarez P. A. Filho       Date: 08/09/08 10:10 AM

Subject: Test is very important

I always search for great resources and tutorials for my collection and I rarely find something about tests. Thanks guys… You’re rock

From: Gurvinder       Date: 07/16/08 09:21 PM

Subject: Testing Issues

It’s a very nice topic discussed in this podcast. While going throug your podcast and i almost found all the files and their conceptual reasons too, the only filei was not able to find was the test.rb which you said is under environments. But i did not find any directory named environments under the rootfolder of my app. insted i found the environments folderunder Config Directory. Is it supposed to be there or i have screwed my folder structure.

 

Hosting Provided By

EngineYard.com fully managed Rails hosting

Sponsored By

New Relic Rails Performance Monitoring

FiveRuns Tuneup

Peepcode Screencasts