small medium large xlarge

Rails Test Prescriptions: Keeping Your Application Healthy


Cover image for Rails Test Prescriptions

Rails Test Prescriptions


Rails Test Prescriptions is a comprehensive guide to testing Rails applications, covering Test-Driven Development from both a theoretical perspective (why to test) and from a practical perspective (how to test effectively). It covers the core Rails testing tools and procedures for Rails 2 and Rails 3, and introduces popular add-ons, including RSpec, Shoulda, Cucumber, Factory Girl, and Rcov.

Please see our New Edition updated for Rails 4.

About this Title

Pages: 368
Published: 2011-02-17
Release: P1.0 (2011-02-16)
ISBN: 978-1-93435-664-7

Your Ruby on Rails application is sick. It’s got bugs. Nobody remembers what that tricky piece of code was supposed to do, and nobody can tell what it actually does. Deadlines are looming, but every time you make the slightest change to the code, something else breaks.

You need Test-Driven Development (TDD), a proven process for improving the design, maintainability, and long-term viability of software. In TDD, the tests come first, and then code is written to match the expectation of the test. Using TDD means writing better code faster.

Ruby on Rails has unparalleled support for TDD. In addition to the tools that Rails has built-in, a large and thriving testing community adds new tools at an accelerating rate. Rails Test Prescriptions is your guide to the entire Rails testing ecosystem.

Containing both practical code examples and discussion of why testing works, this book starts with the most basic features delivered as part of core Ruby on Rails. Once you’ve integrated those features into your coding practice, you’ll want to use popular third-party testing tools such as RSpec, Shoulda, Cucumber, Factory Girl, and Rcov. Rails Test Prescriptions will show you how to use these tools and when they are appropriate. Rails Test Prescriptions covers both Rails 2 and Rails 3.

If you are a Rails programmer who tests code, this book is an invaluable guide to the latest in available testing tools. If you are a Rails programmer who doesn’t test code, then start testing immediately: this book can help.

Read the reviews .

What You Need

Rails 2 or Rails 3

Contents & Extracts

Full Table of Contents

  • Getting Started with Testing in Rails
    • The Goals of Automated Developer Testing excerpt
    • The Basics of Rails Testing
    • Writing Your First Tests excerpt
    • TDD, Rails Style
  • Testing Application Data
    • Testing Models with Rails Unit Tests
    • Creating Model Test Data with Fixtures and Factories
    • Using Mock Objects excerpt
  • Testing User-Facing Layers
    • Testing Controllers with Functional Tests
    • Testing Views
    • Testing JavaScript and Ajax
  • Testing Framework Extensions
    • Write Cleaner Tests with Shoulda and Contexts
    • RSpec
  • Testing Everything All Together
    • Testing Workflow with Integration Tests
    • Write Better Integration Tests with Webrat and Capybara
    • Acceptance Testing with Cucumber
  • Testing Your Tests
    • Using Rcov to Measure Test Coverage
    • Beyond Coverage: What Makes Good Tests?
    • Testing a Legacy Application
    • Performance Testing and Performance Improvement
  • Appendices
    • Sample Application Setup


Noel Rappin is a Senior Consultant at Obtiva. A Rails developer for five years, Noel has spoken at RailsConf and Windy City Rails, and is the author of Professional Ruby on Rails from Wrox Press. A blog relating to this book can be found at