The RSpec Book (Amazon.com) by David Chelimsky (plus a cadre of BDD superstars) is a recent release from The Pragmatic Programmers and a handy addition to any TDD-mad or RSpec-using developer's bookshelf. You can buy a copy from Amazon.com, Amazon.co.uk, or direct from the publisher (more expensive but a PDF version is available).
The RSpec Book is a 400 page book by David Chelimsky (RSpec's primary maintainer), Dave Astels, Zach Dennis, Aslak Hellesøy (of Cucumber fame), Bryan Helmkamp and Dan North. Its aim is to teach you all about RSpec (RSpec 2.0 - specifically) and BDD (Behavior Driven Development) from the ground up and it promises to "help you write better code, write better tests, and delver better software to your users."
Robert C. Martin (a.k.a. Uncle Bob) kicks off the book with a foreword that warns us of what's to come. He says that the book is a trap and isn't really about RSpec. I won't spoil the whole surprise of his delivery but his general point is that the book is focused on teaching you software craftsmanship using BDD (and testing in general) as the framework for putting together well-crafted software. This point is significant because The RSpec Book focuses on the concepts of BDD just as much as it does on the technicalities of RSpec itself.
A Book of Five PartsThe book starts with an extensive Getting Started section headed by a quick chapter summarizing RSpec and Cucumber before moving on to a suite of walkthrough-style chapters dedicated to building a 'code breaker' game. Acceptance Test-Driven Planning is used which essentially means the acceptance tests are written first in the form of Cucumber features so for two chapters you don't get to see any RSpec at all. Once RSpec comes into the mix, though, things move quickly and mocks (doubles) and stubs are introduced quickly. The 'code breaker' game work then continues for a couple of chapters with a brief detour into refactoring.
The second section of the book - Behavior Driven Development - is made up of two code-free chapters that look at BDD from a higher level. A lot of this portion is quite opinionated but if you want to get an overall feel for the BDD process and how different concepts interlock with it, it's a great primer.
The third section of the book - RSpec - proved to be the real "meat" for me. There are several chapters digging solely into the ins and outs of RSpec 2.0 itself. You learn how to use RSpec from the basics up, working through matchers, best practices, mocks, macros, custom formatters, custom matchers, and how the RSpec toolkit can integrate with other tools (such as TextMate). You basically get a 102 page guide to RSpec 2.0 here and that might be worth the price of admission alone.
Sections dedicated to Cucumber and Rails follow on to close the book. I found the Rails section particularly useful having not previously gotten on to the RSpec 2 bandwagon with Rails 3. There are several chapters that each walk through a particular topic, like view specs, controller specs, and model specs. I didn't want to digest the entire set at once and the structure helped me just dig into the parts I was immediately interested in without following each chapter in order. The large number of short and sweet code examples also helps if you're just scanning through looking for some guidance.
Given the significance of The RSpec Book and its time already spent out "in the wild" I asked my Twitter followers for some second opinions to round things off:



In short, I recommend The RSpec Book. The reviews on Amazon seem to be rather mixed so you might want to check them out to get the bigger picture, but I've found the book to be rather useful with its direct narrative style, logical structure, and vast number of short code examples from which to descry some handy techniques.
Who Should Buy It?- Rubyists who want to get up to speed with RSpec 2.0 and, to a lesser extent, Cucumber
- Rails 3.0 developers who want to learn how to do model, controller, view and integration testing with RSpec 2.0
- Anyone with a high-level interest in BDD, even if they're not Ruby developers.
- Anyone who thinks a small press like The Pragmatic Programmers is worth supporting (yes!)
- Anyone expecting a wide overview of TDD and BDD toolsets and libraries. For example, I didn't find any references to Capybara, though Webrat is mentioned.
- Any existing BDD, RSpec 2 and Cucumber gurus.
- Die-hard Test::Unit users.
Here's an overview of the Table of Contents to give you a feel for what's covered:
- Getting Started with RSpec and Cucumber
- Introduction
- Hello (and Installation)
- Describing Features
- Automating Features with Cucumber
- Describing Code with RSpec
- Adding New Features
- Specifying an Algorithm
- Refactoring with Confidence
- Feeding Back What We’ve Learned
- Behaviour-Driven Development
- The Case for BDD
- Writing Software That Matters
- RSpec
- Code Examples
- RSpec::Expectations
- RSpec::Mocks
- Tools And Integration
- Extending RSpec
- Cucumber
- Intro to Cucumber
- Cucumber Detail
- Behaviour-Driven Rails
- BDD in Rails
- Cucumber with Rails
- Simulating the Browser with Webrat
- Automating the Browser with Webrat and Selenium
- Rails Views
- Rails Controllers
- Rails Models
If you want a print copy (no Kindle - sorry!), head to Amazon.com, Amazon.co.uk, or your other favorite book retailer. If a PDF, EPUB or Mobi (Kindle) file is more to your taste, the publisher has those for sale directly - super dooplebloops!
[ad] Red Dirt RubyConf is a hip and happening Ruby conference taking place in Oklahoma City on April 21-22, 2011. Speakers include Aaron 'tenderlove' Patterson, Wayne Seguin, Jeremy McAnally, and Dr Nic Williams (and MANY more great folks).