small medium large xlarge

Effective Testing with RSpec 3: Build Ruby Apps with Confidence

by

Cover image for Effective Testing with RSpec 3

Effective Testing with RSpec 3

Build Ruby Apps with Confidence

by

Build and maintain quality software with RSpec, the popular BDD-flavored Ruby testing framework. This definitive guide from RSpec’s lead developer shows you how to use RSpec to drive more maintainable designs, specify and document expected behavior, and prevent regressions during refactoring. Build a project using RSpec to design, describe, and test the behavior of your code-whether you’re new to testing tools or an experienced developer.


Printed in full color.

Choose Your Format(s)

  • $19.00 In Stock
    • Beta: What do I get?

  • Ebooks are DRM free.

  • Ebook delivery options.

  • The Paper Book will ship on 2017-06-10 (roughly).

About this Title

Skill-meter-3-6
Pages: 275 (est)
Published: 2017-06-10
Release: B4.0 (2017-04-06)
ISBN: 978-1-68050-198-8

RSpec has been downloaded more than 40 million times. Find out how to use this influential Ruby testing framework to iteratively develop a project with the confidence that comes from well-tested code. Effective Testing With RSpec 3 guides you through developing a Ruby project with RSpec, and then explores the individual components in more detail.

First, learn the basics of installing and using RSpec. Then, build a real-world JSON API, using RSpec throughout the process to drive a BDD-style outside-in workflow. Apply an effective test strategy to write fast, robust tests that support evolutionary design through refactoring. The rest of the book provides the definitive guide to RSpec’s components. Use RSpec::Core’s metadata to slice and dice your spec suite in flexible ways. Dig into RSpec::Expectation’s matchers, which can be composed in flexible ways to precisely specify expected outcomes and get good failure messages that help you quickly diagnose the problem. Write fast, isolated tests with RSpec::Mocks test doubles while pushing your code toward simpler interfaces.

The authors, with a combined 20 years of automated testing experience, share useful, actionable testing advice that will help you have a fun, productive testing experience.

What You Need

To follow along with the book, you’ll need Ruby 2.1+. The book will guide you through installing RSpec 3 and setting up a new project to use it.

Contents & Extracts

This book is currently in beta, so the contents and extracts will change as the book is developed.

Introduction

  • Getting Started
    • Getting Started With RSpec
      • Installing RSpec
      • Your First Spec
      • Understanding Failure
      • Sharing Setup (But Not Sandwiches)
      • Your Turn
    • From Writing Specs to Running Them excerpt
      • Customizing Your Specs’ Output
      • Identifying Slow Examples
      • Running Just What You Need
      • Marking Work in Progress
      • Your Turn
    • The RSpec Way
      • What Your Specs are Doing for You
      • Comparing Costs and Benefits
      • Different Types of Specs
      • Guidelines
  • Building an App With RSpec 3
    • Starting On the Outside: Acceptance Specs
      • First Steps
      • Deciding What to Test First
      • Checking the Response
      • Filling in the Response Body
      • Querying the Data
      • Saving Your Progress: Pending Specs
      • Your Turn
    • Testing in Isolation: Unit Specs
      • From Acceptance Specs to Unit Specs
      • Filling in the First Spec
      • Moving On to the Next Spec
      • Implementing the API Behavior
      • Refactoring
      • Handling Failure
      • Defining the Ledger
      • Your Turn
    • Getting Real: Integration Specs excerpt
      • Hooking Up the Database
      • Testing Ledger Behavior
      • Testing the Invalid Case
      • Isolating Your Specs Using Database Transactions
      • Filling In the Behavior
      • Querying Expenses
      • Ensuring the Application Works for Real
      • Your Turn
  • RSpec Core
    • Structuring Code Examples
      • Getting the Words Right
      • Sharing Common Logic
      • Sharing Example Groups
      • Your Turn
    • Slicing and Dicing Specs with Metadata
      • Defining Metadata
      • Reading Metadata
      • Selecting Which Specs to Run
      • Sharing Code Conditionally
      • Changing How Your Specs Run
      • Your Turn
    • Configuring RSpec
      • Command Line Configuration
      • Setting Command-Line Defaults
      • Using a Custom Formatter
      • RSpec.configure
      • Your Turn
  • RSpec Expectations
    • Exploring RSpec::Expectations
      • Parts of an Expectation
      • How Matchers Work
      • Composing Matchers
      • Generated Example Descriptions
      • Your Turn
    • Matchers Included in RSpec::Expectations
      • Primitive Matchers
      • Higher-Order Matchers
      • Block Matchers
      • Your Turn
    • Creating Custom Matchers
      • Using Helper Methods to Delegate to Existing Matchers
      • Defining Matcher Aliases
      • Negating Matchers
      • Using the Matcher DSL to Create a Custom Matcher
      • Defining a Matcher Class
      • Your Turn
  • RSpec Mocks
    • Understanding Test Doubles
      • Types of Test Doubles
      • Usage Modes: Mocks, Stubs, and Spies
      • Origins: Pure, Partial, and Verifying Doubles excerpt
      • Your Turn
    • Customizing Test Doubles
      • Configuring Responses
      • Setting Constraints
      • Your Turn
    • Using Test Doubles Effectively

Author

Myron Marston, a longtime Ruby programmer, has led the development of RSpec since 2012. He works as a senior software engineer at Moz in Seattle. Myron tweets as @myronmarston.

By day, Ian Dees slings code, tests, and puns at a Portland-area test equipment manufacturer. By night, he converts espresso into programming books, including Cucumber Recipes. Ian tweets as @undees.

Upcoming Author Events