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.
For your reading pleasure, here’s the foreword from the book, written by Robert C. Martin:
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.
Thanks for everyone’s patience through the unusually long beta process for this book. We hope you really enjoy The RSpec Book.