Paraje natural de los lances

Review: Effective Testing with RSpec 3

At work, we recently went through the exercise of restructuring our test suite to improve performance. While at it, we decided to put in the effort and rewrite our more wilder tests to better express intent, and increase our level of confidence in their efficacy.

We’ve been using the RSpec testing framework for a couple of years and most of the engineers on the team are intimately familiar with it from previous projects. Now RSpec is a pretty extensive framework that has been through at least a decade of evolution, the feedback loop between the community and the core team is exemplary, and iterative refinements have led to a pretty polished product.

RSpec’s refinements have seen adjustments to both its features and aspects of its philosophy, and when we (at work) got started on restructuring, everyone’s unique experience with the framework made for some pretty lively debate on what we should consider current best practice. Besides generation-influenced syntax and style preferences, there was debate about which types of tests were best suited for our needs —suffice to say, we spent a significant amount of energy working through all this on our way to reaching consensus.

We wrapped up with our restructuring at about the same time Myron Marston and Ian Dees released their book; Effective Testing with RSpec 3. Having just been through the exercise and knowing that Myron is RSpec’s lead maintainer I decided to get myself a copy to —in the least, affirm our efforts.


The Book

This book is suitable for both newcomers and those familiar with the framework. It’s cleanly separated into three parts; Introductory, Real-world and Deep-dives, which can be read independently, yet, the book is written so that the examples latch on to one another making it pleasantly continuous when reading it cover to cover —as I did.

The early chapters as one might expect aim to familiarize the reader with RSpec’s DSL. What was a nice deviation of the norm, is that right from the get-go it establishes its definitions of Behavior Driven Development —BDD, and Test Driven Development —TDD, the reader then learns about RSpec’s DSL as almost a by-product of better familiarizing oneself with the fundamentals of BDD and TDD.

It goes a step further in helping the reader understand the why along with the what by introducing approaches, then explaining their shortcomings before simultaneously refining them and introducing the reader to other aspects of the framework in the process.

As the book progresses it delves deeper into the philosophical aspects of testing and the ways in which RSpec relates, this too is handled tactfully, as the expression of these aspects and the reader’s exposure to RSpec’s features continue in tandem and at a fluid pace.

The authors are careful not to express any one approach to testing as the proverbial silver bullet, but offer enough of their insights and experiences in distilling the topic —by what they consider to be sensible approaches to common scenarios. I found that much of this was relevant to the type of applications I work with, and the reasoning offered along with the insights helps the reader easily discern what is and is not worth doing in their unique situation.


Closing Thoughts

This book certainly lives up to its title of expressing Effective Testing with RSpec 3, by the time you’ve reached its conclusion you’ll have a clear idea of what acceptance, unit and integration tests are good for, whether it’s mocking, stubbing or spying that fits best, what partial and pure doubles can do for you, how to tailor and tune your tests for performance and concise expression, and a trove of useful tips and refinements that really highlight RSpec’s flexibility.

I picked this book up as mainly a means of validating the decisions we had taken, but found invaluable advice and powerful tips that now make it my go-to reference for all things RSpec. If you’re looking for a succinct book on the topic, you’ve found it.

Share Comments