[rspec-users] spec'ing controllers

Pat Maddox mailinglists at patmaddox.com
Wed Dec 16 12:33:56 EST 2009

http://archive.patmaddox.com/blog/2009/1/15/how-i-test-controllers-2009-remix is my take on things.  Due for an update though looks like :)

On Dec 16, 2009, at 8:56 AM, Stefan Kanev wrote:

> Hey guys.
> I switched completely to RSpec and Cucumber this spring and I am really happy with. While I think I've gotten quite good with it, I'm not sure I understand the value of spec'ing controllers (in Rails). I would appreciate if you can give me some suggestions. Let me elaborate:
> The RSpec book suggests mocking models and not integrating vies controller specs. Following that, I usually end up with something like this: http://gist.github.com/257946
> I see a few benefits:
> It helps keeping the controllers simple. For example, while writing that spec I discovered that Topic should have #update_topic_hits (as opposed to inlining it there). That improved the design.
> When mocking gets tricky, I treat this as a code smell and start refactoring. Usually it works out well.
> Specs are faster. Remembering how much time it took to run the functional tests on an old project, I can really appreciate that.
> Small changes in models (or views) don't result in broken controller specs. It took some time, but I can see it now.
> However, I still don't feel too confident about the way I'm doing it. Some of my worries:
> It feels like lots and lots of code. I'm normally at 2:1 test:code, but it feels I'm overdoing it. *feels* is the key word here -- I might be worrying too much.
> I have a similar spec for each RESTful controller. Looks like duplication, but I'm not sure what to do about it
> Often the specs are passing when the code is broken (due to the mocks). While Cucumber catches those errors for me, I'm not sure if they shouldn't be in the specs in some way.
> It's a lot of effort. Eventually ones gets used to it, but I can't decide whether it pays of or not.
> Can you validate (or invalidate) my reasoning? It will be very nice to hear a comment from more experienced rspec users. Comments on the the spec I posted would be appreciated too, of course.
> Thanks very much,
> Stefan
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091216/814c45f3/attachment.html>

More information about the rspec-users mailing list