[rspec-users] using #include in shared behaviours

Tom Stuart tom at experthuman.com
Fri Sep 14 15:38:11 EDT 2007

Hi folks,

Is there any way I can call #include from within a shared behaviour  
without it blowing up?:

> vendor/plugins/rspec/lib/spec/dsl/shared_behaviour.rb:48:in  
> `included': private method `include' called for #<Class:0x3047484>  
> (NoMethodError)

More detail: I have a spec/concerns directory which contains specs  
corresponding to mixins in app/concerns (cf Jamis Buck), so each spec/ 
concerns/*_spec.rb really just contains a shared behaviour which is  
used in the appropriate specs in spec/models (i.e. of those models  
whose app/models counterpart mixes in that concern).

Each such model says require File.dirname(__FILE__) + '/../concerns/ 
animal_spec' and describe Dog do before(:each) do @animal = Dog.new  
end; it_should_behave_like 'all animals' end, which works fine. Some  
of the concern specs need helpers from modules in spec_helper, but  
any attempt to include those modules within the shared behaviour  
blows up as above, so at the moment I'm including the helper modules  
in the model specs themselves. That also works fine, but leaves an  
unpleasant taste since the model spec itself doesn't (syntactically)  
refer to any of the helper methods, so I'd really rather leave the  
#including to the shared behaviour if possible.

Any thoughts?


More information about the rspec-users mailing list