[rspec-users] [OT] Object Mother vs Test Data Builder (was Jay Fields' blog on developer testing)

Stephen Eley sfeley at gmail.com
Fri Feb 6 12:50:18 EST 2009


On Fri, Feb 6, 2009 at 12:17 PM, Fernando Perez <lists at ruby-forum.com> wrote:
>
> The next big step will be specing controllers, as it is more painful
> than models, but now that my controllers are ripped I guess it will be
> easier.

I've stopped.  Mostly because of the question Jay asks in that
article: "Why are you testing?"  I realized I had *no idea* why I was
testing controllers, except that I had been lurking here and reading
the RSpec docs and assumed that was the Way It Was Done.  Finessing
all those mocks and stubs does chew up major time, and I noticed that
the controller code I was spending all that time writing stubs around
wasn't typically code that broke.  Most controllers for most apps are
so boilerplate that if you can trust your framework (Rails or Merb)
you can probably trust the controller.

"If it hurts, you're doing it wrong" is a pretty good principle across
modern development.  I'm sure there are people for whom mocking and
testing every controller action isn't painful, or may even be fun.
I'm not one of them, so there's no point in doing it just for rote.  I
probably _would_ do some controller isolation testing if I had
something complicated to do in an action or if my controllers seemed
prone to breaking and I wasn't sure why.  As David says, knowing more
techniques helps you pick the right one for the right task.

I'm using Cucumber with Webrat for simple request verifications now
and just matching on the output.  I find it's more fun and doesn't
hurt (after I fixed some bugs with the Merb autotest flow) and it
tells me the same stuff as the controller testing, and more, in maybe
a tenth as much time to write.




-- 
Have Fun,
   Steve Eley (sfeley at gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org


More information about the rspec-users mailing list