RSpec Introduction

Peter Marklund

marklunds.com

What is RSpec?

The Test Driven Development Cycle (TDD)

  1. Write a test that specifies a tiny bit of functionality
  2. Ensure the test fails (you haven't built the functionality yet!)
  3. Write only the code necessary to make the test pass
  4. Refactor the code, ensuring that it has the simplest design possible for the functionality built to date

Difference Between TDD and BDD

Unhurriedness

"There's an impossible-to-express quality about test-first design that gives you a sense of unhurriedness. You are actually moving very quickly, but there's an unhurriedness because you are creating little micro-goals for yourself and satisfying them. At each point you know you are doing one micro-goal piece of work, and it's done when the test passes. That is a very calming thing. It reduces the scope of what you have to think about. You don't have to think about everything you have to do in the class. You just have to think about one little piece of responsibility. You make that work and then you refactor it so everything is very nicely designed."

- Martin Fowler

Getting Started with RSpec on Rails

autotest

RSpec Basics

Model Specs

Mocking and Message Expectations

Stubbing

Controller Specs