Prepared exclusively for Jared Rosoff
Beta
Book
Agile publishing for agile developers
The book you’re reading is still under development. As part of our
Beta book program, we’re releasing this copy well before we normally
would. That way you’ll be able to get this content a couple of months
before it’s available in finished form, and we’ll get feedback to make
the book even better. The idea is that everyone wins!
Be warned. The book has not had a full technical edit, so it will con-
tain errors. It has not been copyedited, so it will be full of typos and
other weirdness. And there’s been no effort spent doing layout, so
you’ll find bad page breaks, over-long lines with little black rectan-
gles, incorrect hyphenations, and all the other ugly things that you
wouldn’t expect to see in a finished book. We can’t be held liable if you
use this book to try to create a spiffy application and you somehow
end up with a strangely shaped farm implement instead. Despite all
this, we think you’ll enjoy it!
Throughout this process you’ll be able to download updated PDFs
from your account on
http://pragprog.com. When the book is finally
ready, you’ll get the final version (and subsequent updates) from the
same address. In the meantime, we’d appreciate you sending us your
feedback on this book at
http://pragprog.com/titles/achbd/errata, or by
using the links at the bottom of each page.
Thank you for being part of the Pragmatic community!
Andy & Dave
Prepared exclusively for Jared Rosoff
The RSpec Book
Behaviour Driven Development
with RSpec, Cucumber, and Friends
David Chelimsky
Dave Astels
Zach Dennis
Aslak Hellesøy
Bryan Helmkamp
Dan North
The Pragmatic Bookshelf
Raleigh, North Carolina Dallas, Texas
Prepared exclusively for Jared Rosoff
Many of the designations used by manufacturers and sellers to distinguish their prod-
ucts are claimed as trademarks. Where those designations appear in this book, and The
Pragmatic Programmers, LLC was aware of a trademark claim, the designations have
been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The
Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g
device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of infor mat ion (including program listings) contained herein.
Our Pragmatic courses, workshops, and other pr oducts can help you and your team
create better software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragprog.com.
The team that produced this book includes:
Editor: Jacquelyn Carter
Indexing: Deepak Vohra
Copy edit: Kim Wimpsett
Layout: Steve Peter
Production: Janet Furlow
Customer support: Ellie Callahan
International : Juliet Benda
Copyright
©
2010 The Pragmatic Programmers LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmit-
ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or
otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-10: 1-934356-37-9
ISBN-13: 978-1-934356-37-1
Printed on acid-free paper.
B15.0 printing, July 29, 2010
Version: 2010-7-29
Prepared exclusively for Jared Rosoff
Contents
Important Information for Beta Readers 12
Changes 13
Beta 15.0—July 29, 2010 . . . . . . . . . . . . . . . . . . . . . 13
Beta 14.0—July 22, 2010 . . . . . . . . . . . . . . . . . . . . . 13
Beta 13.0—January 18, 2010 . . . . . . . . . . . . . . . . . . . 14
Beta 12.0—December 3, 2009 . . . . . . . . . . . . . . . . . . 14
Beta 11.0—October 28, 2009 . . . . . . . . . . . . . . . . . . . 14
Beta 10.0—September 22, 2009 . . . . . . . . . . . . . . . . . 14
Beta 9.0—August 28, 2009 . . . . . . . . . . . . . . . . . . . . 15
Beta 8.0—July 17, 2009 . . . . . . . . . . . . . . . . . . . . . . 15
Beta 7.0—June 24, 2009 . . . . . . . . . . . . . . . . . . . . . 15
Beta 6.0—June 17, 2009 . . . . . . . . . . . . . . . . . . . . . 16
Beta 5.0—May 18, 2009 . . . . . . . . . . . . . . . . . . . . . . 16
Beta 4.0—April 13, 2009 . . . . . . . . . . . . . . . . . . . . . . 17
I Getting Started w ith RSpec and Cucumber 18
1 Introduction 19
1.1 Test Driven Development: Where it All Started . . . . . 19
1.2 Behaviour Driven Development: The Next Step . . . . . 21
1.3 RSpec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.4 Cucumber . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.5 The BDD Cycle . . . . . . . . . . . . . . . . . . . . . . . 26
2 Hello 27
2.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2 Hello RSpec . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.3 Hello Cucumber . . . . . . . . . . . . . . . . . . . . . . . 30
Prepared exclusively for Jared Rosoff