Book Image

RSpec Essentials

By : Mani Tadayon
Book Image

RSpec Essentials

By: Mani Tadayon

Overview of this book

This book will teach you how to use RSpec to write high-value tests for real-world code. We start with the key concepts of the unit and testability, followed by hands-on exploration of key features. From the beginning, we learn how to integrate tests into the overall development process to help create high-quality code, avoiding the dangers of testing for its own sake. We build up sample applications and their corresponding tests step by step, from simple beginnings to more sophisticated versions that include databases and external web services. We devote three chapters to web applications with rich JavaScript user interfaces, building one from the ground up using behavior-driven development (BDD) and test-driven development (TDD). The code examples are detailed enough to be realistic while simple enough to be easily understood. Testing concepts, development methodologies, and engineering tradeoffs are discussed in detail as they arise. This approach is designed to foster the reader’s ability to make well-informed decisions on their own.
Table of Contents (17 chapters)
RSpec Essentials
About the Author
About the Reviewers

Using TodoMVC

We'll build a todo list manager based on the TodoMVC application ( This simple, open source application with a rich JavaScript user interface will provide plenty of behavior to specify with BDD. Our implementation will be simpler than the full TodoMVC app, but we'll make sure that our BDD features will work on the full app as well. This will demonstrate how acceptance tests can target both local and deployed instances of an app; in this case, different implementations.

We will first define our feature in a BDD-style RSpec example. Then we'll execute our feature file, which will fail since we won't have any code at that point. We'll then iterate through the development process, building the user interface first, with no Ruby backend. Then we'll move in steps to developing our controller, or API layer, using TDD. Finally, we'll build the model layer that powers our API.

It's important to note that the BDD process is very free flowing, with a natural bouncing...