Confused and frustrated by Rails testing?

Discover how to become the kind of developer who can effortlessly write tests for every feature.

Learn what to test and how to test it. Discover simple, repeatable formulas for writing tests for almost anything in Rails.

Already convinced? See buying options
rtfb

"I don't know what to write tests for"

You've read about all the different types of Rails tests you could write but it's not all clear where you should start.

You could write model specs, controller specs, feature specs, request specs, view specs...the list goes on.

You wonder: it necessary to write all these different kinds of tests? If not, which kinds do you pick, and why?

Am I supposed to write the test first? Or is it okay to write the test after?

"I know I should be testing, I just don't know how to get started"

The tutorials make it seem so easy. Yet as soon as you run into something slightly off the "hello world" path, it all comes tumbling down.

What if your models involve complex associations? How do you test features that involve JavaScript? You spend hours just wrestling with your test environment, trying to get it to work.

You've heard you're not a "real" Rails developer unless you write tests for your code. So apparently you're not a real Rails developer?

"It takes me forever to figure out how to write each test"

You've spent a huge amount of time researching RSpec, Capybara, Factory Bot, MiniTest, and a bewildering number of other testing tools.

Despite all that time spent, half the time when you go to add a test for a feature, you have no idea how to do it. You spend hours messing around before you finally throw your hands in the air and just write the feature in 10 minutes.

Most of your attempts to write tests come to a premature halt because it feels like you're wasting too much time. You quit out of frustration, having nothing to show at the end of your difficulties. You wonder how anyone ever gets good at writing tests.

Introducing: Rails Testing for Beginners

Ebook + Video Package, 189 Pages, 11 Videos

rtfb

Contains the solutions to your testing problems

  • What exactly to write tests for
  • What kinds of tests to write and which kinds to skip
  • How to write tests (even when it's not obvious)
  • How to write integration tests with RSpec and Capybara
  • Mocks and stubs, explained in plain English
  • How to add tests to legacy projects
  • Much more

Table of Contents

  • Part One

    1. Introduction
    2. The Path to Becoming a Confident Rails Tester
    3. My Rails Testing Workflow
    4. How I Make Testing a Habit
    5. Why I Recommend Against Using Cucumber
    6. Mocks and Stubs
    7. Pointless Types of Tests to Avoid
    8. How to Deal With Complex Factory Bot Associations
    9. A Repeatable, Step-by-Step Process for Writing Rails Integration Tests With Capybara
    10. How to Write a Test When the Test Implementation Isn't Obvious
    11. Factories and Fixtures
    12. Characterization Tests
    13. Page Objects
    14. Testing Private Methods
    15. How I Approach Test Coverage Metrics
    16. How I Test JavaScript-Heavy Applications
    17. Common Causes of Flapping Tests
    18. Using Tests as a Tool to Wrangle Legacy Projects
    19. Continuous Integration
    20. A Rails Testing Hello World
    21. A Rails Model Test Hello World
  • Part Two

    1. Setting Up Our Sample Application
    2. Building Our First Resource
    3. Our First Real Feature Spec
    4. Our First Real Model Spec
    5. The Book Resource
    6. My Book Specs
    7. More Advanced Tests: Book Authorship
    8. My Authorship Test
    9. Orders and Line Items
    10. My Order and Line Item Tests
    11. De-Obscuring Our Tests Using Factories
    12. Feature Spec for Order Creation
    13. Where to Go From Here

Video Walkthroughs

Follow the book's testing tutorial without fear of getting stuck.
A Rails Testing Hello World (11:25)
A Rails Model Test Hello World (6:08)
Setting Up Our Sample Application (6:00)
Building Our First Resource (9:31)
Our First Real Feature Spec (11:41)
Our First Real Model Spec (8:54)
The Book Resource (18:30)
More Advanced Tests: Book Authorship (16:17)
Orders and Line Items (17:51)
De-Obscuring Our Tests Using Factories (13:13)
Feature Spec for Order Creation (14:49)

Video Walkthrough Sample

Purchase Rails Testing for Beginners

Choose a package below to get instant access to Rails Testing for Beginners.

Professional Package

Book + Videos + Slack

  • The 189-page book in PDF, EPUB and MOBI
  • 2 hours of video walkthroughs so you never get stuck
  • RTFB Slack access - chat with other Rails devs about testing
Buy Now ($89)
Comes with 100% money-back guarantee

Basic Package

Just the Book

  • The 189-page book in PDF, EPUB and MOBI
  • 2 hours of video walkthroughs so you never get stuck
  • RTFB Slack access - chat with other Rails devs about testing
Buy Now ($49)
Comes with 100% money-back guarantee

FAQs

How long is the book?

The book is 189 pages long.

What's the format of the book?

When you purchase, you get a zip file containing PDF, EPUB and MOBI formats. No print version as of now.

What testing frameworks and tools are covered?

RSpec, Capyabara, Factory Bot, and Faker (no Minitest). What's more important than the testing framework or other tools though are the testing principles covered that apply no matter what set of tools you're using.

What versions of Rails/RSpec are covered?

Rails 6.0.1 and RSpec 3.8.

What if I buy it and I don’t like it? Do I get my money back?

Yes. I offer a 100% no-questions-asked money-back guarantee.

About the Author

I'm Jason Swett. I'm a developer, speaker, trainer, author and host of The Rails with Jason Podcast.

I've taught programming classes and given tech talks all over the US and the world, including conferences like RailsConf, RubyConf India and RubyHACK. My corporate teaching clients have included Deloitte, VMware, Liberty Mutual and HP.

I've spoken or taught in the US, India, Nigeria, Bulgaria and the Netherlands.