Everyday Rails Testing with RSpec

A practical approach to test-driven development

Real-world advice for adding reliable tests to your Rails apps with RSpec, complete with expanded, exclusive content and a full sample application. Now updated for Rails 4.0, Capybara 2.1, Factory Girl 4.2, and RSpec 2.14!

3829 readers

100% Happiness guarantee Learn more

Minimum: $14.00

Suggested: $19.00+

Ways to buy

  • Free sample read /download
  • 3829 readers
  • 138 pages
  • 34,687 words
  • 100% complete
  • Book language: English
  • Translations available: 2 translations
  • Updated

Translations

About the Book

Have you gotten your hands dirty with a Rails application or two, but lack reliable test coverage? Does your application testing consist of a series of browser clicks, hoping you cover everything? Or do you just cross your fingers and hope for the best that everything will just work?

Don't worry, everyone has been there at some point--and while testing and test-driven development are important aspects of Rails development, many tutorials gloss over these components. In Everyday Rails Testing with RSpec, I'll show you how I got past that hurdle, increasing my code's trustworthiness and saving untold time in browser-based testing.

Everyday Rails Testing with RSpec contains six chapters based on content from the Everyday Rails blog, along with six additional chapters exclusive to the book and complete code for a simple, but tested Rails application. I will also commit to keeping the code and book content current through Rails 4.0, at no extra cost to you.

About the Author

The Leanpub Unconditional, No Risk, 100% Happiness Guarantee

♥♥♥♥♥

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks. We process the refunds manually, so they may take a few days to show up. See full terms.

If you buy a Leanpub book you get all the updates to the book for free! All books are available in PDF, EPUB (for iPad) and MOBI (for Kindle). There is no DRM. There is no risk, just guaranteed happiness or your money back.

Table of Contents

  • Preface to this edition
  • Acknowledgements
  • 1. Introduction
    • Why RSpec?
    • Who should read this book
    • My testing philosophy
    • How the book is organized
    • Downloading the sample code
    • Code conventions
    • Discussion and errata
    • About the sample application
  • 2. Setting up RSpec
    • Gemfile
    • Test database
    • RSpec configuration
    • Generators
    • Questions
    • Exercises
  • 3. Model specs
    • Anatomy of a model spec
    • Creating a model spec
    • The new RSpec syntax
    • Testing validations
    • Testing instance methods
    • Testing class methods and scopes
    • Testing for failures
    • More about matchers
    • DRYer specs with describe, context, before and after
    • Summary
    • Question
    • Exercises
  • 4. Generating test data with factories
    • Factories versus fixtures
    • Adding factories to the application
    • Simplifying our syntax
    • Associations and inheritance in factories
    • Generating more realistic fake data
    • Advanced associations
    • How to abuse factories
    • Summary
    • Exercises
  • 5. Basic controller specs
    • Why test controllers?
    • Why not test controllers?
    • Controller testing basics
    • Organization
    • Setting up test data
    • Testing GET requests
    • Testing POST requests
    • Testing PATCH requests
    • Testing DELETE requests
    • Testing non-CRUD methods
    • Testing nested routes
    • Testing non-HTML controller output
    • Summary
    • Exercises
  • 6. Advanced controller specs
    • Getting ready
    • Testing the admin and user roles
    • Testing the guest role
    • Summary
    • Exercise
  • 7. Controller spec cleanup
    • Shared examples
    • Creating helper macros
    • Using custom RSpec matchers
    • Summary
    • Exercises
  • 8. Feature specs
    • Why feature specs?
    • What about Cucumber?
    • Additional dependencies
    • A basic feature spec
    • From requests to features
    • Adding feature specs
    • Debugging feature specs
    • A little refactoring
    • Including JavaScript interactions
    • Capybara drivers
    • Summary
    • Exercises
  • 9. Speeding up specs
    • Optional terse syntax
    • Mocks and stubs
    • Automation with Guard and Spork
    • Tags
    • Other speedy solutions
    • Summary
    • Exercises
  • 10. Testing the rest
    • Testing email delivery
    • Testing file uploads
    • Testing the time
    • Testing web services
    • Testing rake tasks
    • Summary
    • Exercises
  • 11. Toward test-driven development
    • Defining a feature
    • From red to green
    • Cleaning up
    • Summary
    • Exercises
  • 12. Parting advice
    • Practice testing the small things
    • Be aware of what you’re doing
    • Short spikes are OK
    • Write a little, test a little is also OK
    • Strive to write feature specs first
    • Make time for testing
    • Keep it simple
    • Don’t revert to old habits!
    • Use your tests to make your code better
    • Sell others on the benefits of automated testing
    • Keep practicing
    • Goodbye, for now
  • More testing resources for Rails
    • RSpec
    • Rails testing
  • About Everyday Rails
  • About the author
  • Colophon
  • Change log
    • February 23, 2014
    • January 24, 2014
    • January 14, 2014
    • October 28, 2013
    • October 7, 2013
    • September 4, 2013
    • August 27, 2013
    • August 21, 2013
    • August 8, 2013
    • August 1, 2013
    • May 15, 2013
    • May 8, 2013
    • April 15, 2013
    • March 9, 2013
    • February 20, 2013
    • February 13, 2013
    • December 11, 2012
    • November 29, 2012
    • August 3, 2012
    • July 3, 2012
    • June 1, 2012
    • May 25, 2012
    • May 18, 2012
    • May 11, 2012
    • May 7, 2012

Last updated

This Book is for Sale Through Leanpub

Authors and publishers use Leanpub to publish amazing in-progress and completed books like this one.

Leanpub_logo_medium

Read

Leanpub has a wide selection of in-progress and completed books available to browse, purchase, and enjoy.

Browse the Bookstore

Write

Leanpub is free for authors and publishers to use. We pay authors or publishers 90% royalties minus 50 cents per sale.

Write a Book