[rspec-users] What do you think of this controller spec?

Pat Maddox pergesu at gmail.com
Sun Dec 24 15:53:02 EST 2006


Here's a controller spec I wrote, it's for a very simple RESTful
controller (well, aren't all RESTful controllers simple? :)

I've created a couple spec helper methods to refactor some of the
common code...for example, require_login_and_correct_user creates two
specifications: one for when the user isn't logged in, and one when
the user is logged in but requests someone else's book.  do_request
automatically calls do_get/post/put/delete depending on what's
implemented.

Here's all the code:

books_controller.rb: http://pastie.caboo.se/29469
books_controller_spec.rb: http://pastie.caboo.se/29470
spec_helper.rb: http://pastie.caboo.se/29471

The specs just feel somewhat unwieldy to me...maybe it's because the
controller code is very simple and elegant, and the spec looks big and
bloated in comparison.  Also, it feels like it's taking me a lot
longer to write the controller specs with all these individual
verifications.

Am I just tripping for no reason, and the specs look fine?  What would
you change?  Also I know that the controller code could be improved by
using the finder on the association, this is just how I have it for
now.  I'm interested in how the specs could be better.

I'll be understanding if I don't get a response for a few days :)
Merry Christmas everybody!

Pat


More information about the rspec-users mailing list