rspec_tutorial.pdf - RSpec About the Tutorial RSpec is a unit test framework for the Ruby programming language RSpec is different than traditional xUnit

rspec_tutorial.pdf - RSpec About the Tutorial RSpec is a...

This preview shows page 1 - 6 out of 10 pages.

RSpec i About the Tutorial RSpec is a unit test framework for the Ruby programming language. RSpec is different than traditional xUnit frameworks like JUnit because RSpec is a Behavior driven development tool. What this means is that, tests written in RSpec focus on the "behavior" of an application being tested. RSpec does not put emphasis on, how the application works but instead on how it behaves, in other words, what the application actually does. This tutorial will show you, how to use RSpec to test your code when building applications with Ruby. Audience This tutorial is for beginners who want to learn how to write better code in Ruby. After finishing this tutorial, you will be able to incorporate RSpec tests into your daily coding practices. Prerequisites In order to benefit from reading this tutorial, you should have some experience with programming, specifically with Ruby. Disclaimer & Copyright Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute, or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness, or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected]
RSpec ii Table of Contents About the Tutorial ............................................................................................................................................ i Audience ........................................................................................................................................................... i Prerequisites ..................................................................................................................................................... i Disclaimer & Copyright ..................................................................................................................................... i Table of Contents ............................................................................................................................................. ii 1. RSPEC INTRODUCTION ...................................................................................................... 1 RSpec Environment .......................................................................................................................................... 1 2. RSPEC BASIC SYNTAX ......................................................................................................... 4 The describe Keyword ..................................................................................................................................... 4 The context Keyword ....................................................................................................................................... 4 The it Keyword ................................................................................................................................................ 5 The expect Keyword ........................................................................................................................................ 5 3. RSPEC WRITING SPECS ...................................................................................................... 6 4. RSPEC MATCHERS ........................................................................................................... 11 Equality/Identity Matchers ............................................................................................................................ 11 Comparison Matchers .................................................................................................................................... 12 Class/Type Matchers ..................................................................................................................................... 13 True/False/Nil Matchers ................................................................................................................................ 14 Error Matchers ............................................................................................................................................... 15 5. RSPEC TEST DOUBLES ...................................................................................................... 17 6. RSPEC STUBS ................................................................................................................... 19 7. RSPEC HOOKS .................................................................................................................. 22 8. RSPEC TAGS ..................................................................................................................... 25
RSpec iii 9. RSPEC SUBJECTS .............................................................................................................. 26 10. RSPEC HELPERS ............................................................................................................ 28 11. RSPEC METADATA ........................................................................................................ 30 12. RSPEC FILTERING .......................................................................................................... 33 RSpec Formatters .......................................................................................................................................... 34 Failed Examples ............................................................................................................................................. 37 13. RSPEC EXPECTATIONS .................................................................................................. 38
1 RSpec is a unit test framework for the Ruby programming language. RSpec is different than traditional xUnit frameworks like JUnit because RSpec is a Behavior driven development tool.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture