# Constants defined in initializer not found when running gems:install in test

**URL:** <https://www.ruby-forum.com/t/constants-defined-in-initializer-not-found-when-running-gems-install-in-test/166323>\
**Category:** Rails\
**Created:** [April 23, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/constants-defined-in-initializer-not-found-when-running-gems-install-in-test/166323 "2009-04-23T21:39:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@tobi](https://www.ruby-forum.com/u/tobi)\
**Post date:** [April 23, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/constants-defined-in-initializer-not-found-when-running-gems-install-in-test/166323/1 "2009-04-23T21:39:01Z")

</div>

Dear all,

I am setting some constants in an initializer, which are used in  
validations in my models.  
When I run

RAILS\_ENV=test rake gems:install

I get missing constant errors for these, but not when I run

RAILS\_ENV=development rake gems:install

It only happens for the gems:install task in test.  
Everything else (e.g. rake test) works as expected.  
What could be the problem?

Thanks for your help

Tobi

---

<div class="post-metadata">

**Author:** ![tobi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@tobi](https://www.ruby-forum.com/u/tobi)\
**Post date:** [April 25, 2009, 1:42am UTC](https://www.ruby-forum.com/t/constants-defined-in-initializer-not-found-when-running-gems-install-in-test/166323/2 "2009-04-25T01:42:03Z")

</div>

The problem you ran into was the same one as this thread:

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/56c560bd46347d12](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/56c560bd46347d12)

and both are caused by load\_application\_classes trying to load all  
your models at startup. That routine does nothing when  
config.cache\_classes is false (the default in development mode, but  
not in test).

As a quick workaround, try setting config.cache\_classes to false in  
environments/test.rb to get the gems installed.

–Matt J.
