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

Chapter 6. Driving a Web Browser with Capybara

In the preceding five chapters, we have covered all the important features of RSpec, focusing on unit tests for libraries and command-line tools. Now it is time to build on this foundation to learn how to write end-to-end tests for web applications. In order to test web applications in a realistic way, we need to a way to interact with a web browser in our tests. The Capybara gem allows us to control a variety of browsers from within our test code to interact with a web application and make assertions about the behavior of the application within the browser.

In this chapter, we'll get familiar with how Capybara works, and how it integrates with RSpec. Unlike the preceding chapters, in which we developed the application code alongside our test code, this time we are not going to build a new application but point our browser, via Capybara, to existing websites. This way, we can focus on understanding the test code. Nevertheless, don't worry, we...