[rspec-users] rpec_scaffold and nested resources

Rick DeNatale rick.denatale at gmail.com
Tue Dec 18 17:58:31 EST 2007

I've got a love-hate relationship with script/generate rspec_scaffold

If you are using non-nested controllers/resources it's great.  I love
the spec skeletons it generates.

But I find myself doing this, where Y is and existing set of
model/controller ... representing a resource:

1) script/generate rspec_scaffold x ....

At this point rake spec passes.

2) edit config/routes.rb and change it from:
      map.resources :ys
      map.resources :xs

      map.resources :ys do | y |
          y.resources :xs

 At this point rake spec fails on the routes and controller specs for
x, no big surprise. The controller needs to change as well.

This is followed by a manual editing session of BOTH the controller
and the specs, with lots of fairly tedious changes.

Of course most of this might be laid to the rails scaffold generator
not being able to generate nested resource controllers directly as a
prerequisite to rspec_scaffold, unless there's something y'all know
that I don't. (Well I'm sure that y'all know lots that I don't but I
don't know if it's relevant to this).  But the changes to the
controller are much easier than the changes to the specs.

I was starting to think about writing a plugin/tool to address this,
but I was wondering if anyone had any insight or had already started
down this path.

Rick DeNatale

My blog on Ruby

More information about the rspec-users mailing list