Behaviour-Driven Development (BDD) gives you the best of Test Driven Development, Domain Driven Design, and Acceptance Test Driven Planning techniques, so you can create better software with self-documenting, executable tests that bring users and developers together with a common language.
Get the most out of BDD in Ruby with The RSpec Book, written by the lead developer of RSpec, David Chelimsky.
This book uses Rails 3, RSpec 2, Ruby 1.8.7, and Cucumber 0.9.2
About this Book
- 450 pages
- Release: P2.1 (2012-09-13)
- ISBN: 978-1-93435-637-1
You’ll get started right away with RSpec 2 and Cucumber by developing a simple game, using Cucumber to express high-level requirements in language your customer understands, and RSpec to express more granular requirements that focus on the behavior of individual objects in the system. You’ll learn how to use test doubles (mocks and stubs) to control the environment and focus the RSpec examples on one object at a time, and how to customize RSpec to “speak” in the language of your domain.
You’ll develop Rails 3 applications and use companion tools such as Webrat and Selenium to express requirements for web applications both in memory and in the browser. And you’ll learn to specify Rails views, controllers, and models, each in complete isolation from the other.
Whether you’re developing applications, frameworks, or the libraries that power them, The RSpec Book will help you write better code, better tests, and deliver better software to happier users.
Caution! You’ve fallen for a trap. You’ve picked up this book thinking it was about RSpec. Fortunately, you decided to read the foreword. Good! That gives me the opportunity to tell you about the mistake you just made and possibly save you from an unexpected fate.
You see, this book isn’t about RSpec at all. Oh, RSpec is certainly mentioned. There are lots of examples of how to use it. There’s even a very detailed reference manual in Part III. But that’s all just part of an insidiously clever deception, because this book is not about RSpec.
Perhaps you thought you might read about Cucumber? After all, Part IV is named “Cucumber.” Oh, these authors are clever; God they are! They’ve littered this book with examples and details that tell you all about Cucumber in all its intricacies and all its copious fiddledy-bits. There’s even a section on using it with Rails and Webrat and all the other gory things that you’ll need to become a Cucumber expert. But this book is not about Cucumber.
No. This book is not about RSpec. And this book is not about Cucumber. This book is about. . .
I’m not sure I should tell you. I mean, once the secret gets out, it’s liable to cause mayhem. If it ever got out who the audience for this book really is, if the masses learned of the diabolical plan being executed in their midst, I’m not sure our civilization would survive.
You see. . . (come closer, and cover this part with your hand so nobody else can see it). . . you see, this book is not for. . . (covered?). . . it’s not for Ruby programmers!
There, I’ve said it! Now don’t panic, and don’t drop the book— whatever you do, don’t drop the book! Hold on tight, and keep it covered. Don’t let anyone else see.
Yes, you see, this book is not about RSpec. It’s not about Cucumber, It’s not for Ruby programmers. This book is for. . . (covered again?). . . it’s for all programmers!
Keep a good tight grip. I know it’s hard. Don’t look around suspiciously. Don’t draw attention to yourself. Just try to stay calm, breathe normally, and keep reading.
Yes, all the code is in Ruby. Yes, all the examples use RSpec and Cucumber to one degree or another. Yes, if you read this book, you will learn RSpec, Cucumber, and things about Ruby and Rails and Webrat that you didn’t know before. No doubt about it. Remember, the best lies are near-truths.
Here’s the thing. While you read this book, you will think you are learning about all those cool tools. You will think “Oh, cool, I’m learning RSpec and Cucumber.” But you will be learning something else at the same time! Something unexpected. Something unadvertised. Something, perhaps, unwelcome.
As you read these pages, a hidden meme will creep into your mind—a meme of such potency and power that it is likely to change everything about the way you program. And not just how you program in Ruby! If you read this book, that meme will change the way you program in Java, C#, Python, or (oh, God, the thought) COBOL! This book will change the way you code—period!
Worse, you don’t have to be a Ruby programmer to be infected by this meme. As I said, these authors are clever. Their unholy plan is to infect all programmers with this meme. You see, they’ve cleverly constructed the Ruby code in this book so that it can be understood by (gasp) any programmer at all! I mean, this is worse than Fluoridation!
Any programmer who picks up this book will be infected by the meme. And the meme is subtle. And the meme is persistent. And the meme will have its way. And when it does, our industry will never be the same again. Are you willing to risk that?
What is this meme? What name shall we give it? The meme is legion! It’s not just Agile, though Agile is there. It’s not just TDD and BDD, though both are there. It’s not just Continuous Integration, Acceptance Test–Driven Development, Acceptance Test–Driven Planning, or even Extreme Programming, though all those things are present in the meme.
No, the meme is more than any one of those things. The meme is a synergistic witches brew of some of the most contagious and effective ideas of the past two decades. The meme is. . .
Dare I say it?
The meme is. . .
. . . Craftsmanship.
Robert C. Martin
Contents and Extracts
- Getting Started with RSpec and Cucumber
- Describing Features
- Automating Features with Cucumber
- Describing Code with RSpec excerpt
- 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
- Code Examples excerpt
- Tools And Integration
- Extending RSpec
- Intro to Cucumber
- Cucumber Detail
- Behaviour-Driven Rails
- BDD in Rails
- Cucumber with Rails excerpt
- Simulating the Browser with Webrat
- Automating the Browser with Webrat and Selenium
- Rails Views
- Rails Controllers
- Rails Models
Comments and Reviews
—Ian Dees Software Engineer
Some authors would be satisfied with just writing the definitive guide for a technology. These folks go a step further, and show you insider tips that will keep your tests clean and maintainable.
—Marcus Ahvne software developer Valtech
The second generation of tools for the XP generation explained by their creators and maintainers. Awesome, a must read.
—Matt Wynn independent programmer and coach
The RSpec Book teaches you much more than how to use RSpec’s features; it teaches you how to write code the way the RSpec team does: patiently, and with great precision and clarity. There is something here for everyone: beginners are given plenty of gentle attention but there is some real meat for the more experienced reader to chew on, too.
—Craig Demyanovich 8th Light, Inc.
This book covers the territory of writing great software, and the authors are your experienced guides. If you follow the map that they have drawn, you’ll learn to write only the code that you need, and you’ll write it simply and clearly. You’ll come home from this journey with some experiences that will have immediate and lasting effects on the code in your editor and the code yet to flow from your fingertips.
—Aaron Bedra principal Relevance Inc.
The RSpec Book is a fantastic introduction to all things BDD. It goes much deeper than just testing to provide you with the right tools you need to fully embrace the ideas that the framework has baked in.