Continuous Testing_ With Ruby, Rails, an - Rady_ Ben.pdf

(5164 KB) Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
878678705.051.png
Continuous Testing
with Ruby, Rails, and JavaScript
Ben Rady
Rod Coffin
The Pragmatic Bookshelf
Dallas, Texas • Raleigh, North Carolina
878678705.057.png 878678705.058.png
Many of the designations used by manufacturers and sellers to distinguish their products
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, PragProg and the linking g device are trade-
marks 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
information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products 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://pragprog.com .
The team that produced this book includes:
Jacquelyn Carter (editor)
Potomac Indexing, LLC (indexer)
Kim Wimpsett (copyeditor)
David J Kelly (typesetter)
Janet Furlow (producer)
Juliet Benda (rights)
Ellie Callaghan (support)
Copyright © 2011 Pragmatic Programmers, LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, 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-13: 978-1-934356-70-8
Printed on acid-free paper.
Book version: P1.0—June 2011
878678705.059.png
Contents
Acknowledgments
.
.
.
.
.
.
.
.
.
.
vii
Preface
.
.
.
.
.
.
.
.
.
.
.
.
.
ix
2.1
Exploring the Chapters
x
2.2
Who This Book Is For
xi
2.3
Working the Examples
xii
2.4
Online Resources
xii
1.
Why Test Continuously?
.
.
.
.
.
.
.
.
.
1
1.1
What Is Continuous Testing?
2
1.2
Beyond Automated Tests
2
1.3
Enhancing Test Driven Development
4
1.4
Continuous Testing and Continuous Integration
4
1.5
Learning to Test Continuously
6
Part I — Ruby and Autotest
2.
Creating Your Environment
.
.
.
.
.
.
.
.
11
2.1
Getting Started with Autotest
11
2.2
Creating a Potent Test Suite with FIRE
16
2.3
Writing Informative Tests
17
2.4
Writing Fast Tests
23
2.5
Writing Reliable Tests
27
2.6
Creating an Exhaustive Suite
33
2.7
Closing the Loop
35
3.
Extending Your Environment
.
.
.
.
.
.
.
.
37
3.1
Using Autotest Plugins
37
3.2
Adding Event Hooks
40
3.3
Creating Plugins
45
3.4
Closing the Loop
52
878678705.001.png 878678705.002.png 878678705.003.png 878678705.004.png 878678705.005.png 878678705.006.png 878678705.007.png 878678705.008.png 878678705.009.png 878678705.010.png 878678705.011.png 878678705.012.png 878678705.013.png 878678705.014.png 878678705.015.png 878678705.016.png 878678705.017.png 878678705.018.png 878678705.019.png 878678705.020.png 878678705.021.png 878678705.022.png 878678705.023.png 878678705.024.png 878678705.025.png
4.
Interacting with Your Code
.
.
.
.
.
.
.
.
53
4.1
Understanding Code by Changing It
53
4.2
Comparing Execution Paths
58
4.3
Learning APIs Interactively
61
4.4
Making It till You Fake It
68
4.5
Closing the Loop
75
Part II — Rails, JavaScript, and Watchr
5.
Testing Rails Apps Continuously
.
.
.
.
.
.
.
79
5.1
Building Our Rails App
80
5.2
Creating a CT Environment with Watchr
80
5.3
Validating Style Sheets
82
5.4
Migrating Continuously
84
5.5
Running Rails Specs Fast
86
5.6
Closing the Loop
90
6.
Creating a JavaScript CT Environment
.
.
.
.
.
91
6.1
Using Node.js
92
6.2
Checking Syntax with JSLint
93
6.3
Writing FIREy Tests with Jasmine
94
6.4
Running Tests Using Node.js and Watchr
97
6.5
Closing the Loop
100
7.
Writing Effective JavaScript Tests
.
.
.
.
.
.
103
7.1
Mocking Out the Browser
103
7.2
Testing Asynchronous View Behavior
107
7.3
Testing View Aesthetics
112
7.4
Closing the Loop
115
Part III — Appendices
A1.
Making the Case for Functional JavaScript
.
.
.
.
119
A1 1 Is JavaScript Object Oriented or Functional?
119
A1 2 Introducing Modit
122
A1 3 Functional Programming in JavaScript
127
A2.
Gem Listing
.
.
.
.
.
.
.
.
.
.
.
.
133
A3.
Bibliography
.
.
.
.
.
.
.
.
.
.
.
.
135
878678705.026.png 878678705.027.png 878678705.028.png 878678705.029.png 878678705.030.png 878678705.031.png 878678705.032.png 878678705.033.png 878678705.034.png 878678705.035.png 878678705.036.png 878678705.037.png 878678705.038.png 878678705.039.png 878678705.040.png 878678705.041.png 878678705.042.png 878678705.043.png 878678705.044.png 878678705.045.png 878678705.046.png 878678705.047.png 878678705.048.png 878678705.049.png 878678705.050.png 878678705.052.png 878678705.053.png 878678705.054.png 878678705.055.png 878678705.056.png
Zgłoś jeśli naruszono regulamin