The Complete Guide to Rails Testing

Jason Swett

About the Book

Contains the solutions to your testing problems

  • What are the different kinds of Rails tests?
  • What are all the Rails testing tools and how do I use them?
  • Which testing framework should I use (RSpec or Minitest)?
  • How can I make testing a habitual part of my development work?
  • What level of test coverage should I shoot for?
  • How do I add tests to an existing Rails project?
  • Much more

The different kinds of Rails tests

There are several different types of RSpec tests you can use. I show which ones to use and which ones to skip.

The various Rails testing tools and how to use them

Covers RSpec, Factory Bot, Capybara, VCR and WebMock.

How to decide which testing framework to use

Explains how to decide between the two big testing frameworks, RSpec and MiniTest.

How to make testing a habit

It’s not enough to know how to write tests, you actually have to do it. I show you how to make testing a habit.

What level of test coverage to shoot for

Shows what level of test coverage to shoot for (hint: it’s not a number).

How to add tests to an existing Rails project

Adding tests to an existing Rails project is a whole different ballgame from testing a greenfield app. I show you how.

How to set up a new Rails project for testing

I show you exactly how I set up all my new Rails projects.

How to decide when to do test-driven development

Are you testing “wrong” if you don’t do TDD? I show you my approach to test-driven development.

Ruby DSLs (domain-specific languages)

Gain a solid understanding of how DSLs (domain-specific languages) work so you can understand the DSLs of RSpec, Factory Bot and Capybara.

Factory Bot

Installation, configuraiton, factory definitions, nested factories, traits, callbacks and transient attributes.

RSpec Syntax

Ruby blocks, let and let! vs. instance variables, describe and context, RSpec’s DSL.

System Specs

When to write system specs, how to write system specs, a formula for writing system specs for most features.

Model Specs

What kinds of model specs to write and what kinds not to, the difference between testing implementation and behavior, much more.

Request Specs

What request specs are, the scenarios where request specs are useful vs. where they’re not.

Mocks and Stubs

Test doubles, the difference between mocks and stubs, when to use mocks and stubs.

VCR and WebMock

Why to use VCR and WebMock, installation and configuration, how to use VCR and WebMock.