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

File-based configuration management

What we're going to do is to put all of our configurations into a file and load them from the file when we start our app. This is quite simple to get started with, but we'll have to evolve in order to support some important basic needs. We'll start with a config file, which we'll name .env, which is a commonly used convention, although the name is actually not important. Here are the contents of the file:


The format is that of variable declarations in a Bash shell script. This is appropriate because using environment variables will force us to use Bash variables in the end. We avoid the confusion of type conversions by declaring the variables in the same way. Had we used JSON or another more powerful format, we would have to contend with conversion of types for integers, arrays, and other non-String types allowed by the format.

The next step is to load these variables into...