Contexts, mocks, and stubs, oh my!

Trotter Cashion

Presented by: Trotter Cashion

Talk Description

My talk will cover the benefits of using contexts, mocks, and stubs in unit tests. These three concepts are in heavy use by RSpec users, but seem to have minimal adoption by the bulk of Ruby developers. In addition, many developers do not even realize that contexts are an option within TestUnit. This talk will serve to enlighten these developers by showing them how to make contexts, mocks, and stubs work for them. I will explain how contexts can be used to bring organization to large test classes by organizing tests into related groups of object state. In addition, I will explain how to use mocks and stubs to easily test hard to test components, while cautioning against the dangers of going overboard.


Trotter Cashion has been using Ruby for almost the past two years. At EastMedia, he worked on, the first OpenID server in Rails. In addition, he worked on the cms for He is now employed as an Application Developer at, a Rails based video sharing site. He is currently writing a Short Cut (e-book) for Addison Wesley about Refactoring and REST.