Stubbing Unloaded Dependencies

Writing fast tests often means testing without loading the rest of the application. When you want to stub a method on a class that isn't loaded, how do you do it? There are many ways, and here we'll quickly look at five of them, four of which have no test performance impact at all.

Note: After the publiciation of this screencast, RSpec gained a "stub_const" function. Using this is generally easier than creating an empty class, but provides similar results. The trade-offs are slightly different from the empty class approach, but almost all of the disussion in this screencast holds.