Table of Contents

Transcript

Download

Play


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

0 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.