[rspec-users] DRY specs for RESTful controllers

David Chelimsky dchelimsky at gmail.com
Wed Aug 29 09:44:31 EDT 2007

On 8/29/07, Tom Stuart <tom at experthuman.com> wrote:
> Hi,
> I'm developing a RESTful Rails application whose code and specs are
> becoming increasingly repetitive: every controller does pretty much
> the same set of things (give or take the occasional twiddle), for
> example, and so every controller spec is almost identical modulo some
> names, constants and strings.
> The make_resourceful plugin, which autogenerates the boilerplate REST
> actions, has gone a long way towards DRYing out the controller side
> of things, but I haven't seen any examples of nice patterns for doing
> something similar on the spec side.
> I'm starting small here: I don't even know what the authorised idiom
> is for sharing behaviours between specs, since I've only used shared
> behaviours within a single spec. (Stick something -- a behaviour?
> some kind of helper? -- in a module? What to call the module file?;
> where to put it?) Furthermore it's obvious that I don't want just to
> "inherit" a single static spec across multiple controllers, but
> rather to instantiate a parameterised spec so that it talks about the
> right classes, the right routes, the right instance variable.

There has been discussion of parameterized shared behaviours, but the
current implementation doesn't do that. I just added a feature request
for this outlining my thoughts on how it should work:
Please feel free to add comments to that item in the tracker. You can
add them here, but they'll likely get lost if you do. Adding them to
the tracker ensures that when we go to implement something your
comments are considered.


> *Furthermore* furthermore, controllers occasionally deviate from the
> standard RESTful template in a variety of ways, so it'd be nice to be
> able to "override" the appropriate bits after declaring that
> it_should_behave_like "ARestfulController" (or whatever).
> I fear the solution to my requirements is ultimately on par with
> implementing some kind of make_resourceful-for-specs plugin, which is
> way beyond what I've got time to do at the moment, but I still feel
> there's plenty of room for gentle incremental improvement on my
> current position without going crazy with speculative generality. Any
> advice much appreciated!
> Cheers,
> -Tom
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list