Update: Avdi has generously made the Outside-In episode of Ruby Tapas embeddable for this post–see below. Thanks, Avdi!
Once you know the basic mechanics of testing, how do you bring it all together into a consistent testing habit or routine? I get asked this a lot by people who’ve recently finished Everday Rails Testing with RSpec or are generally still getting comfortable with this facet of development. While there are a number of approaches, I like to go outside-in by starting with a high-level spec, using it to drive the desired behavior of my software, and dropping down to unit tests to suss out the finer details of a feature. It’s an organic process, to be sure, and one that can take some practice before becoming second nature.
Lately I’ve been catching up on Ruby Tapas, Avdi Grimm’s excellent series of bite-sized videos on Ruby. If you’re not already a subscriber, I highly recommend checking it out. $9 a month gives you access to a large library of videos, growing at a rate of two per week. If you need additional motivation, episode 120, Outside-In, is a wonderful demonstration of the outside-in testing process in action, and a great example of an approach I try to follow, myself.
A few observations:
This isn’t the only Ruby Tapas episode dedicated to writing tests–and even episodes not focused on testing show how your test suite is an integral part of growing and refactoring your code base. Again, I can’t suggest checking it out enough. And, though I’ve mentioned it before, I suggest checking out How I Test on Railscasts. It’s a few years old now, and some of the syntax has changed a bit, but it’s still a wonderful demonstration of this same approach to testing. In fact, this video is what inspired me to write my book in the first place. It’s a free clip, so if you haven’t watched it yet, please take 15 minutes to do so.
I stand with the Black community against systemic racism, police violence and brutality, intolerance, and hate in the United States and worldwide. We must all demand better from our leaders, and ourselves. Stop tolerating intolerance.
While you're here, please consider making a donation to Black Girls CODE, who do great, important work to provide opportunity to underprivileged girls interested in tech, or any organization working toward equity and safety for all, not just the privileged. Thank you.
If you liked my series on practical advice for adding reliable tests to your Rails apps, check out the expanded ebook version. Lots of additional, exclusive content and a complete sample Rails application.
Ruby on Rails news and tips, and other ideas and surprises from Aaron at Everyday Rails. Delivered to your inbox on no particular set schedule.