[rspec-users] Spec helper configuration problem

Ben Mabey ben at benmabey.com
Fri Nov 27 14:59:38 EST 2009

Andrew Premdas wrote:
> Hi all,
> I have a rails application whose specs run on about eight different 
> boxes, but I can't get them to work on my integration server. The bit 
> thats breaking concerns some modules that I have in 
> spec/support/modules which are loaded by
> the following line in spec_helper
>     # get any macros etc
>     Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
> one of these modules includes the other modules, and this generates 
> the following stacktrace
>      /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant OrderSpecHelper::BasketSpecHelper (NameError)
>      from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in `const_missing'
>      from ./spec/helpers/../support/modules/order_spec_helper.rb:2
>      from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
>      from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
>      from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:158:in `require'
> the line causing this is order_spec_helper.rb:2
>   module OrderSpecHelper
>     include BasketSpecHelper
> and BasketSpecHelper is defined in 
>     /support/modules/basket_spec_helper.rb
> and is coded something like
>   module BasketSpecHelper
>     ...
> I wonder if anyone has any ideas about the cause of this problem or 
> some ideas about possible solutions

I've ran into similar issues.  The problem in my case was the my 
integration server was running linux but our dev boxes were OSx.  The 
issue was file ordering being different for the Dir::[] method on the 
OSes.  Try adding a sort call like so:

Dir[File.dirname(__FILE__) + "/support/**/*.rb"].sort.each {|f| require f}


More information about the rspec-users mailing list