Testing Ruby with RSpec: The Complete Guide

Video description

This course offers a comprehensive overview of the RSpec testing library for the Ruby programming library. RSpec is the most popular Ruby Gem of all time, with over 300 million downloads to date. If you are new to the topic, testing is the practice of writing code that confirms that other code works as expected. Tests control regressions, which are changes to the code that breaks the program.

The benefits of testing extend beyond the codebase. Adopting a test-driven approach will also make you a better developer. Tests force you to think critically about a program and its features: classes, objects, methods, and more.

This course begins with the essentials and proceeds to more complex topics, including installation, project initialization, Test-Driven Development (TDD), let variables, before and after hooks, subjects, shared examples, shared context, built-in matches, mocks and doubles, instance doubles, and class doubles.

At the completion of this course, you will have acquired hands-on Ruby testing experience with this awesome RSpec library.

What You Will Learn

  • Learn how to install RSpec and initialize the project
  • Cover Test-Driven Development (TDD), methods, and hooks
  • Learn about subjects, shared examples, and shared context
  • Explore built-in matchers such as not_to, all, eq, and more
  • Learn to create a test double
  • Understand instance doubles and class doubles


Programmers who want to explore the fundamentals of testing and TDD and intermediate Ruby developers interested in upgrading their skillset will benefit from this course. Knowing any text editor (VS Code is recommended) would be beneficial. No previous testing experience is needed!

About The Author

Boris Paskhaver: Boris Paskhaver is a NYC-based web developer and software engineer with experience in building apps in React/Redux and Ruby on Rails. Raised in New Jersey, he graduated from the Stern School of Business at New York University in 2013 with a double major in business economics and marketing. Since graduation, his work has taken him in a wide variety of directions—he spent years in marketing, then financial services, and now the tech industry.

He has worked everywhere, from a 50-person digital agency to an international tech powerhouse with thousands of employees. He always had a love of learning but struggled with the traditional resources available for education. His goal is to create comprehensive courses that break down complex details into small, digestible pieces.

Publisher resources

Download Example Code

Table of contents

  1. Chapter 1 : Introduction
    1. Welcome to RSpec
    2. Unit Tests versus End-to-End (E2E) Tests
    3. Installing RSpec
    4. Starting a Project with rspec --init
    5. Test-Driven Development
    6. The Describe Method
    7. The it Method
    8. The Expect and Eq Methods
    9. Reading Failures
    10. Making the Specs Pass
    11. Multiple Examples in Example Group
    12. Fixing Failing Specs Again
    13. Reducing Duplication - Before Hooks and Instance Variables
    14. Reducing Duplication: Helper Methods
    15. Problems with Mutation
    16. Reducing Duplication: The let Method
    17. Custom Error Messages
    18. The context Method and Nested Describes
    19. Before and After Hooks
    20. Nested Logic: Hooks
    21. Nested Logic: Overwriting Let Variables
  2. Chapter 2 : Subjects, Shared Examples, and Shared Context
    1. Implicit Subject
    2. Explicit Subject
    3. described_class
    4. One-Liner-Example-Syntax
    5. Shared Examples with include_examples
    6. Shared Context with include_context
  3. Chapter 3 : Built-In Matchers
    1. The not_to Method
    2. Equality Matchers I (eq and eql)
    3. Equality Matchers II (equal and be)
    4. Comparison Matchers
    5. Predicate Matchers
    6. all Matcher
    7. be Matcher (Truthy, Falsy and Nil Values)
    8. change Matcher
    9. contain_exactly Matcher
    10. start_with and end_with Matchers
    11. have_attributes Matcher
    12. include Matcher
    13. raise_error Matcher
    14. respond_to Matcher
    15. satisfy Matcher
    16. not_to Method
    17. Compound Expectations
  4. Chapter 4 : Mocks
    1. Create a Test Double
    2. Set Up Our Test Movie
    3. Replacing an Object with a Double
    4. Receive Counts
    5. The allow Method
    6. Matching Arguments
    7. Instance Doubles
    8. Class Doubles
    9. Spies I
    10. Spies II
  5. Chapter 5 : Conclusion
    1. Conclusion

Product information

  • Title: Testing Ruby with RSpec: The Complete Guide
  • Author(s): Boris Paskhaver
  • Release date: August 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781839219474