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

Step 2 – defining the API

We're going to add some backend code in Ruby so that we have an API server for our view to connect to. This will allow us to save our todo list between browser sessions. It will also lay the foundation for many new features that we might want to add in the real world, such as sharing lists with other people, user management, and sending e-mail reminders about unfinished todos.

So where do we start with our backend code? With BDD, we keep going from the outside in. We'll just make a small change to our AngularJS service to rely on an HTTP API. That will give us a list of endpoints that our API server needs to handle and a good starting place for our work on the backend. This is one of the benefits of BDD. It points the way to the exact code we need to write along the way, taking the guesswork out of where to start.

Let's replace static/js/mock_todo_list.js with static/js/todo_list.js with the following contents:

'use strict';

// define the model to handle the data...