Testing Rails Applications

Goal

To teach you testing we are going to start with the basics and have you learn by doing through small challenges and then a final large.

When you have completed this curriculum you should understand:

  • what tests are
  • why they're used
  • how they're used
  • what types of tests exist
  • what types of frameworks exist
  • some additional concepts in testing such as doubles, stubs, spies, and Webmock
  • how to write tests
  • how to break tests
  • how to fix tests

Requirements

We're going to be working with:

  • Ruby on Rails
  • A command line program
  • A text editor of your choice

This is not a self-paced curriculum. You should use the discussion sections on each page to make sure everyone is together!

Notable things

As you might have noticed, we're assuming you've already been to a RailsBridge workshop before or have otherwise already explored a Rails app, and are ready for deeper knowledge.

This curriculum is written for Rails 5. Things will get awkward / broken if you're using an earlier version of Rails, so if you skipped the Installfest, you need to upgrade to Rails 5 now.

Tips for everyone

  • When adding code, it's awesome for students to walk through the code line by line and say out loud what is happening. (i.e., "The string is being stored in the instance variable" or "The method snorgle is being defined"). If you do it every time, you'll get really comfortable with the vocabulary of Rails!
  • Error messages are your friend! Read them carefully, and practice understanding what Rails is telling you. Seeing an error and just diving back into your code is a natural reaction, but stop! Then read, think, and talk about what the error means before fixing it.

Working Effectively and Efficiently

We highly recommend you do the following:

  • Bring up your terminal and open 2 tabs:
    • One is for regular terminal stuffs
    • One will be for IRB (a.k.a. Rails console). We'll explain later.
  • Open your browser fresh or hide any windows you already have open.
    • Bring up one window with two tabs
    • One for this content
    • One for interacting with your app.
  • Open your text editor and don't close it.
  • Hide all extra applications. Turn off Twitter, Facebook, IM, and all other distractions.

By minimizing the number of things you interact with, you reduce the amount of time spent switching between them and the context lost as you work through the lessons. Having 50 tabs open in your web browser gets confusing.

Next Step: