O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mock Tips

My opinion about the best way to use mock objects changes every few months. I’ll try some mocks, they’ll work well, I’ll start using more mocks, they’ll start getting in the way, I’ll back off, and then I’ll think, “Let’s try some mocks.” This cycle has been going for years and I have no reason to think it’s going to change anytime soon.

That said, some guidelines always hold true.

The Ownership Rule

Don’t mock what you don’t own. In other words, use test doubles only to replace methods that are actually part of your application, and not part of an external framework. (Note that we violated this rule in this chapter when we stubbed ActiveRecord methods like update_attributes.)

Prescription 19Don’t mock what you don’t own.

One reason ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required