[rspec-devel] spec_helper required multiple times

Brandon Keepers bkeepers at gmail.com
Tue Nov 6 10:15:52 EST 2007


spec_helper gets run multiple times during a spec run.  Throw this at  
the bottom of spec_helper:

   @x ||= 0
   puts "requiring spec_helper: #{@x += 1}"

Is this expected behavior?  This seems to be caused by #require not  
expanding paths, so it requires spec_helper once per unique require  
statement (once per spec directory).

It is resolved by wrapping the require at the top of each spec file  
with expand_path:

   require File.expand_path(File.dirname(__FILE__) + '/../../ 
spec_helper')

It seems to me like this is something that require should do  
automatically.  Thoughts?

Brandon


More information about the rspec-devel mailing list