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

MMFs by example

We'll be developing an app that manages a todo list. Let's develop an MMF for the app. The MMF is an important element of organizing our specification in BDD. First, let's start with the justification of value. The common structure for these justifications is in three parts:

As a …
In order to …
I want to …

The idea is to specify the role of the user first. Then we write what the value is to that user. Finally, we describe how the user achieves that value. The feature itself is only in the last part, but the first two parts provide important context. We can also expand each part to have multiple declarations, simply by using the conjunction and.

Without further delay, let's write a justification for a todo list manager app:

As a user
In order to keep track of what I need to do
And in order to keep track of what I've already finished
I want to add todo items to a list
And I want to mark them as completed

The preceding description seems obvious and not remarkable. We'll work on...