On Thu, Sep 24, 2009 at 8:13 PM, Eric Hahn <eric at ingroup.com>
wrote:>
> The controllers themselves are using josevalim''s wonderful
inherited_resources gem, so they are incredibly small - I''m basically
looking for something like this on the rspec side...
(*googling*) Aha. Looks a lot like the old make_resourceful,
resource_controller, and resources_controller plugins. Not sure I
agree with his choice to drive it by class inheritance rather than
module inclusion, though. Seems like it might be pretty fragile --
which he corroborates with his note that RSpec in standard controller
isolation mode breaks it.
> I''ve played around with a lot of approaches, but cannot figure out
a clean pattern in which variables such as @model_name are scoped visible to the
''it'' descriptions AND the example blocks. ?I''m
probably missing some wonderful clean ruby-way of doing this.
Class variables may be your friend here, since the "it" descriptions
are really akin to method definitions and therefore declared at the
class level.
That said, though: I have to wonder if it''s a good idea to have so
much magic that all of your controller specs now declare themselves
almost completely in shared examples. That makes the behavior
specification invisible, at least at a fast code glance. Half the
reason I write specs is because typing them makes me take a moment to
think about the behavior I want. If your controllers are _so_ uniform
that you not only don''t have to write them, you don''t have to
write
the _specs_ for them -- then why test them? Why not just make sure
your inherited_resources suite has a thorough set of specs, and trust
it to act consistently, only spec''ing the variances?
(Yes, this is sort of a cynic''s view. It''s the same reason I
eventually stopped using make_resourceful -- too much magic. The
actual meat of my controllers was so well-hidden that I found myself
looking at the plugin''s docs constantly just to remember what my own
application did.)
--
Have Fun,
Steve Eley (sfeley at gmail.com)
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org