From: Pat Maddox Date: 2007-11-15T11:19:14+09:00 Subject: Re: rspec questions: same file? mocks objects as params? On Nov 14, 2007 6:08 PM, Giles Bowkett wrote: > > 2) If I use mocks, am I supposed to pass them as parameters to my > > production code? > > If I understand correctly you shouldn't change your production code at all. Well, not quite. If you're retrofitting tests onto existing code, you'll often need to change the production code to work with mocks. That's because most code that isn't written with testability in mind tends to be too coupled, because it's just easier to write code that way. So you certainly could have to break those dependencies when you're writing tests after the fact. But you're right, the whole point of mocks is to allow you to swap in a different object with the same interface. Mocking isn't a silver bullet of course...code that's easy to mock isn't necessarily well-design, but in general there are fewer dependencies - a Good Thing. Pat