On Mon, Oct 27, 2008 at 9:35 AM, Pat Maddox <[EMAIL PROTECTED]> wrote: > Matt Wynne <[EMAIL PROTECTED]> writes: > >> Pat - are you going solo too? > > Nope, I'm trying to teach RSpec/BDD to an organization that currently > doesn't use it and has 0% test coverage. It's interesting, to say the > least. They're good devs, but even so, the effects of not writing tests > first (or even at all) are painfully evident when trying to get the > codebase under test, and especially to change stuff. Really puts your > "working effectively with legacy code" chops to work :)
One major point which I failed to make is that a heavily determining factor for me is confidence. How much confidence does a new test inspire? Clearly, a full-stack acceptance test ought to inspire a good deal of confidence. A mocked-out unit test considerably less so. As I've said before, I see three major benefits to unit tests: * Drive the design of objects * Provide regression tests * Serve as examples of how to use the code Mock based controller specs don't provide as much regression value as acceptance tests, unless you've got a bunch of weird little pathways that you want to unit test. But most Rails apps these days aren't like that - we have REST + "skinny controller / fat model" to thank for that. Ben, I think it was you who mentioned that you like using mocks in controller specs because it helps with interface discovery. While I agree that mocks can be a great tool for interface discovery, I'm finding that to be decreasingly important in controllers. They're just so damn simple, for the most part. Remember, mocks are just one of the tools we use to improve design. Refactoring is another one. I've found that when writing controllers, mocks provide little upfront design value, and the bulk of design value I get comes from refactoring. Now, I will add that I've written a crapload of controller specs over the last few years, and have developed a personal style that minimizes logic in the controllers. So I don't generally spend a lot of brain cycles on controller design. They become patterns...think Cypher from the Matrix: "all I see is blonde, brunette, redhead..." When it comes to controllers specs, mocks provide the most value by isolating from the model and db - the specs run faster, and you don't have to worry about model validations. But if you minimize controller logic, you can write acceptance tests that give you confidence that your controllers work, and then controller specs become unnecessary overhead. Pat _______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
