[rspec-users] reusable specs - almost there

David Green
Sat, 04 Aug 2007 13:06:24 -0000

I have a lot of controllers with virtually identical functionality for most
actions. I''ve been using shared behaviours to DRY things up a bit, but
I
still have to create separate behaviours for each context before I can use
the shared behaviours

what I have now is a generic file which contains all the behaviours and
examples common to all the controllers, and that file gets loaded from an
actual controller spec. The generic file knows which controller to test by
calling kontroller(), which is defined in the controller spec.

here''s a very simplified example:
http://pastebin.com/m6b47bae9

It works great when I run the specs individually, but when I use rake, specs
begin to fail and i think it''s because the value of kontroller() is set
to
whatever it returns the first time it gets called. Here''s the rake
output
from running the specs shown above:


FooController
.FooController
.

Finished in 0.041793 seconds
2 examples, 0 failures

I would expect it to print FooController and then BarController ...
interestingly, if I insert ''puts kontroller.to_s'' *outside* of
the describe
block, then it does output the names of both controllers as expected.

does anyone know of a solution?
thanks

dave

--
View this message in context: