small medium large xlarge

Rails 5 Test Prescriptions: Build a Healthy Codebase


Cover image for Rails 5 Test Prescriptions

Rails 5 Test Prescriptions

Build a Healthy Codebase


Does your Rails code suffer from bloat, brittleness, or inaccuracy? Cure these problems with the regular application of test-driven development. You’ll use Rails 5.2, Minitest 5, and RSpec 3.7, as well as popular testing libraries such as factory_bot and Cucumber. Updates include Rails 5.2 system tests and Webpack integration. Do what the doctor ordered to make your applications feel all better. Side effects may include better code, fewer bugs, and happier developers.

<img src=“” style=“float: left; border: none; text-decoration: none;”;/>

This edition uses Rails 5.2

The edition using Rails 4 is available here: Rails 4 Test Prescriptions

Customer Reviews

This is my favorite Rails testing book! I love the prescriptions. It’s like collecting
big thoughts and organizing little ideas within them.

- Maricris S. Nonato

Senior Ruby on Rails Developer, Premiere Speakers Bureau

I found Noel Rappin’s Rails 4 Test Prescriptions so helpful, and I was pleased to see
Noel’s humor and thorough explanations continue in this edition. Every time I
thought, “What about such-and-such?” it was covered within a paragraph or two.
Best of all, this edition does more than update the previous edition—there is a substantial
amount of new material. I’m planning to read it again and reference it often!

- Tara Scherner de la Fuente

Software Developer, Allovue

If you’re new to Rails, or new to the idea of testing within Rails, this thorough
book will definitely set you on the right path.

- Sean Miller

Solution Developer and Consultant

Sometimes testing sucks. This book magically makes testing not suck; it makes
it easy and rewarding with well-written explanations. It is the essential resource
for any developer testing Rails applications. It’s more than just a testing primer;
developers will learn how to create optimal and efficient test suites for Rails. A
must-read for beginners and seasoned programmers alike.

- Liz Abinante

Senior Software Engineer, GitHub

Noel is an exceptional teacher and it shows! This book is a balanced and pragmatic
introduction to testing your Rails applications. It effectively communicates the
benefits of various approaches while providing sufficient context on situations
where the approach might be less applicable.

- Ashish Dixit

Software Engineer

See All Reviews

Choose Your Format(s)

  • $25.95 In Stock
  • Ebooks are DRM free.

  • Ebook delivery options.

What You Need

Ruby 2.5, Rails 5.2

Contents & Extracts

  • Acknowledgments
  • Preface
    • Who You Are
    • What’s in This Book
    • What You’ll Need
    • A Word About Tools, Best Practices, and Teaching TDD
    • Changes in This Edition
    • Online Resources
  • A Test-Driven Fable
    • Testing First Drives Design
    • What Is TDD Good For?
    • When TDD Needs Some Help
    • What You’ve Done
  • Test-Driven Development Basics
    • Infrastructure
    • The Requirements
    • Installing RSpec
    • Where to Start? excerpt
    • Running the Test
    • Making the Test Pass
    • The Second Test
    • Back on Task
    • Adding Some Math
    • The First Date
    • Using the Time Data
    • What You’ve Done
  • Test-Driven Rails
    • Let’s Write Some Rails
    • The Days Are Action-Packed
    • Who Controls the Controller?
    • A Test with a View
    • Testing for Failure
    • What You’ve Done
  • What Makes Great Tests
    • The Big One
    • Cost and Value
    • SWIFT: The Five Qualities of Valuable Tests
    • What You’ve Done
  • Testing Models excerpt
    • What Can You Do in a Model Test?
    • What Should You Test in a Model Test?
    • Okay, Funny Man, What Makes a Good Set of Model Tests?
    • Refactoring Models
    • A Note on Assertions per Test
    • Testing What Rails Gives You
    • Testing ActiveRecord Finders
    • Testing Shared Modules and ActiveSupport Concerns
    • Writing Your Own RSpec Matchers
    • What You’ve Done
  • Adding Data to Tests
    • What’s the Problem?
    • Fixtures
    • Factories
    • Dates and Times
    • What You’ve Done
  • Using Test Doubles as Mocks and Stubs
    • Test Doubles Defined
    • Creating Stubs
    • Mock Expectations
    • Using Mocks to Simulate Database Failure
    • Using Mocks to Specify Behavior
    • More Expectation Annotations
    • Mock Tips
    • What You’ve Done
  • Integration Testing with Capybara and Cucumber
    • A Field Guide to Integration and System Tests
    • Setting Up Capybara
    • Using Feature Tests to Build a Feature
    • What to Test in an RSpec System Test
    • Outside-in Testing
    • Making the Capybara Test Pass
    • Retrospective
    • Setting Up Cucumber
    • Writing Cucumber Features
    • Writing Cucumber Steps
    • Advanced Cucumber
    • Is Cucumber Worth It?
    • What You’ve Done
  • Testing JavaScript: Integration Testing
    • Integration-Testing JavaScript with Capybara
    • Let’s Talk About Drivers
    • Making the Test Pass
    • Webpack in Developer Mode
    • What You’ve Done
  • Unit-Testing JavaScript
    • Setting Up JavaScript Unit Tests
    • Writing a Sample Test
    • TDD in JavaScript
    • Jasmine Matchers
    • Testing Ajax Calls
    • Using testdouble.js
    • Connecting the JavaScript to the Server Code
    • What You’ve Done
  • Testing Rails Display Elements
    • Testing Routes
    • Testing Helper Methods excerpt
    • Testing Controllers and Requests
    • Simulating Requests
    • What to Expect in a Request Spec
    • Older Rails Controller Tests
    • Testing Mailers
    • Testing Views and View Markup
    • Using Presenters
    • Testing Jobs and Cables
    • What You’ve Done
  • Minitest
    • Getting Started with Minitest
    • Minitest Basics
    • Running Minitest
    • Minitest Setup
    • Mocha
    • System Tests and Others
    • Minitest Helper Tests
    • Minitest and Routing
    • What You’ve Done
  • Testing for Security
    • User Authentication and Authorization
    • Adding Users and Roles
    • Restricting Access
    • More Access-Control Testing
    • Using Roles
    • Protection Against Form Modification
    • Mass Assignment Testing
    • Other Security Resources
    • What You’ve Done
  • Testing External Services
    • External Testing Strategy
    • The Service Integration Test
    • Introducing VCR
    • Client Unit Tests
    • Why an Adapter?
    • Adapter Tests
    • Testing for Error Cases
    • Smoke Tests and VCR Options
    • The World Is a Service
    • What You’ve Done
  • Troubleshooting and Debugging
    • General Principles
    • The Humble Print Statement
    • Git Bisect
    • RSpec or Minitest Bisect
    • Pry
    • Common Rails Gotchas
    • What You’ve Done
  • Running Tests Faster and Running Faster Tests
    • Running Smaller Groups of Tests
    • Running Rails in the Background
    • Running Tests Automatically with Guard
    • Writing Faster Tests by Bypassing Rails
    • Recommendations for Faster Tests
    • What You’ve Done
  • Testing Legacy Code
    • What’s a Legacy?
    • Set Expectations
    • Getting Started with Legacy Code
    • Test-Driven Exploration
    • Dependency Removal
    • Find the Seam
    • Don’t Look Back
    • What You’ve Done


Noel Rappin is a Principal Software Engineer at Table XI, and is the author of multiple technical books. Before joining Table XI, Noel ran internal training at Groupon, and has a Ph.D. in educational technology and user-centered design from the GVU Lab at the Georgia Institute of Technology. Find Noel online at