The Complete Guide to Rails Testing

If you've tried to learn Rails testing, maybe you've been stuck on these common testing questions...

"What should I write tests for?"

You know you should be testing but you're not sure exactly what to test. The advice you've read doesn't seem to apply when the rubber meets the road.

How can I make testing a habitual part of my development workflow?

Maybe you conceptually understand how to write tests but you still aren't actually doing it. What's the difference between you and the people who write tests for all their code? Do they just have more discipline? What's the secret?

"What test framework should I use, MiniTest or RSpec?"

You know that MiniTest and RSpec are the two most popular testing frameworks for Rails, but you're not sure how to decide which one to use. There seem to be good (and strongly expressed!) arguments on both sides. How do you pick?

What level of test coverage do I need?

You've seen the tools that measure code coverage but you're not sure how much is really needed. 100%? 60%? 80%? Is there such a thing as too much testing?

Do I need to be doing TDD 100% of the time in order to be doing it "right"?

You've heard about test-driven development, and maybe you've even done a little TDD, but it's not clear how to do TDD all the time. Do you have to do TDD all the time in order to be a "real" tester? Is TDD even a good thing?

What are the various Rails testing tools and how do I use them?

Factory Bot, Faker, RSpec, VCR, WebMock...there are so many testing tools. What are they all for? Do you need them all?

Imagine what it would feel like to have really strong testing skills

You'd write tests as easily as you write regular code.

When you're comfortable with testing, you don't have to think hard about it. The tests just flow out. In fact, all your coding gets easier, because the tests you write help guide you forward.

You wouldn't have to force yourself to write tests because testing is just a habit.

To developers who are good at testing, writing tests isn't an extra chore. Writing tests isn't something they have to remember to do. It's just a normal part of the coding process. Furthermore, it's a fun and enjoyable part of the coding process.

You would choose your testing tools with confidence.

When you understand what the available testing tools are and why different teams choose different tools, it becomes easy to make the right choice for yourself. You can make the decision once and never worry about it again.

You would know how to do TDD and when to use it.

It would be 100% clear to you how to TDD any feature—IF you wanted to. And when you don't want to TDD a feature, you'll know why you're making that choice.

Introducing: the Complete Guide to Rails Testing

234 Pages, E-book Format

The Complete Guide to Rails Testing

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

What's in the book

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.
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.

Purchase the Complete Guide to Rails Testing

Choose a package below to get instant access to the Complete Guide to Rails Testing.

Professional Package

Book + Slack Access (for Businesses)

  • The 234-page book in PDF, EPUB and MOBI
  • CGRT Slack access - chat with other Rails devs about testing
  • Up to 10 developers may access the material
  • Custom invoicing for your financial records
Buy Now ($99)
Comes with 100% money-back guarantee

Basic Package

Book + Slack Access (for Individuals)

  • The 234-page book in PDF, EPUB and MOBI
  • CGRT Slack access - chat with other Rails devs about testing
  • Up to 10 developers may access the material
  • Custom invoicing for your financial records
Buy Now ($49)
Comes with 100% money-back guarantee

FAQs

How long is the book?

The book is 234 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, Capybara, 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?

There's nothing in the book that's version-specific.

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.