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

The BDD process begins

Now let's run the feature. We can't get too excited yet since we expect our tests to all fail. We haven't written any code, after all, but we can confirm that we've got everything configured properly and get started with the BDD process. Let's run our feature for the first time:

I've only shown the top part of the output for the sake of brevity. While the feature was running, you should also have seen Mozilla Firefox launch and display an error message before it closed itself:

Not very impressive. Note that we set APP_HOST to the apparently random value of http://localhost:9292 and since we have no web server running at that URL, or even any code that could be run yet, it makes sense that we got a failure. Another point to pay attention to is that Capybara's error message was as follows:

Unable to find field "What needs to be done?"

It would have been nice for Capybara to tell us that the browser was not able to even connect to the URL we supplied, but the error message...