[rspec-users] Interesting shared behaviour side-effect

Tom Stuart tom at experthuman.com
Sun Oct 21 06:21:21 EDT 2007


On 21 Oct 2007, at 11:01, Wincent Colaiuta wrote:
> Not actually a big deal; seeing as the specs don't have any side-
> effects and running them twice is harmless, and in any case getting
> rid of the nesting (putting all the specs in a single shared
> behaviour block) gets rid of the duplicate. But I'm wondering, is
> this a bug? Feature? Am I abusing shared behaviours?

FWIW, this is something that also bites me frequently when wanting to  
write multiple shared behaviours for mixins. I've resorted to  
abandoning "higher-order" shared behaviours and using helper methods  
instead (def it_should_behave_like_my_mixin; describe ... :shared =>  
true do ... end; describe ... :shared => true do ... end;  
describe ... do it_should_behave_like ... end; end) to bundle  
together several related behaviours for injection into multiple specs.

(As an aside, these helpers often have to be parametric in the target  
class so that their before(:each) blocks can create new instances --  
this all feels pretty clumsy but I just couldn't get it to work with  
an instance created in before(:each) in the target spec because the  
shared behaviours get run multiple times and it looks like external  
state leaks between them.)

So yes, +1, someone please explain the right way to do these things! ;-)

Cheers,
-Tom


More information about the rspec-users mailing list