# Rake gems not working in test environment

**URL:** <https://www.ruby-forum.com/t/rake-gems-not-working-in-test-environment/166298>\
**Category:** Rails\
**Created:** [April 23, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/rake-gems-not-working-in-test-environment/166298 "2009-04-23T17:22:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lee](https://www.ruby-forum.com/u/lee)\
**Post date:** [April 23, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/rake-gems-not-working-in-test-environment/166298/1 "2009-04-23T17:22:32Z")

</div>

I am unable to get ‘rake gems’ to run in my test environment. I am  
using the following command:

rake gems RAILS\_ENV=test

and getting the error below. rake gems RAILS\_ENV=development works ok.

Any thoughts appreciated.

Trace output:

\*\* Invoke gems (first\_time)  
\*\* Invoke gems:base (first\_time)  
\*\* Execute gems:base  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
rake aborted!  
no such file to load – list  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`require’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:155:in `require' /Users/leelon/work/cbox/app/models/filter.rb:10 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ dependencies.rb:155:in`require’  
/Users/leelon/work/cbox/app/models/event\_subscription.rb:6  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`require’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:155:in `require' /Users/leelon/work/cbox/app/models/subscription.rb:8 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ dependencies.rb:155:in`require’  
/Users/leelon/work/cbox/app/models/property.rb:7  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`require’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:155:in `require' /Users/leelon/work/cbox/app/models/member_entity.rb:6 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ dependencies.rb:155:in`require’  
/Users/leelon/work/cbox/app/models/accessibility.rb:6  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`require’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:155:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ dependencies.rb:262:in`require\_or\_load’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:221:in `depend_on' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ dependencies.rb:133:in`require\_dependency’  
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:368:in  
`load_application_classes' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:in`each’  
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:in  
`load_application_classes' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:in`each’  
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:in  
`load_application_classes' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:185:in`process’  
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in  
`send' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in`run’  
/Users/leelon/work/cbox/config/environment.rb:13  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`require’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:153:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ dependencies.rb:521:in`new\_constants\_in’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:153:in `require' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/tasks/misc.rake:3 /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in`call’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in`each’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in`invoke\_with\_call\_chain’  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
1.8/monitor.rb:242:in `synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in`invoke\_with\_call\_chain’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in `invoke' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/tasks/gems.rake:21 /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in`call’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in`each’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in`invoke\_with\_call\_chain’  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
1.8/monitor.rb:242:in `synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in`invoke\_with\_call\_chain’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:588:in  
`invoke_prerequisites' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:585:in`each’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:585:in  
`invoke_prerequisites' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:577:in`invoke\_with\_call\_chain’  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
1.8/monitor.rb:242:in `synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in`invoke\_with\_call\_chain’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in `invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in`invoke\_task’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in`each’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in`standard\_exception\_handling’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in`run’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in  
`standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in`run’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/bin/rake:31  
/usr/bin/rake:19:in `load’  
/usr/bin/rake:19

---

<div class="post-metadata">

**Author:** ![lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lee](https://www.ruby-forum.com/u/lee)\
**Post date:** [April 23, 2009, 6:17pm UTC](https://www.ruby-forum.com/t/rake-gems-not-working-in-test-environment/166298/2 "2009-04-23T18:17:41Z")

</div>

I’ve now discovered this problem is being caused by a require  
statement in my models:

require ‘list’

where ‘list’ is list.rb in the acts\_as\_list plugin.

I am unable to remove this as it is needed by a standalone Ruby  
program that uses the same models as the Rails environment (and  
ActiveRecord).

I still don’t understand why ‘rake gems’ works in development but not  
in test - that is, rake gems only complains about the “require ‘list’”  
statement when run in test. Any thoughts appreciated.

---

<div class="post-metadata">

**Author:** ![lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lee](https://www.ruby-forum.com/u/lee)\
**Post date:** [April 24, 2009, 6:27am UTC](https://www.ruby-forum.com/t/rake-gems-not-working-in-test-environment/166298/3 "2009-04-24T06:27:02Z")

</div>

I have solved this problem by extending the load path in  
environment.rb:

config.load\_paths += %W( #{RAILS\_ROOT}/vendor/plugins/acts\_as\_list/lib/  
active\_record/acts )

rake gems RAILS\_ENV=test is now able to resolve my “require ‘list’”  
statements in my models.

---

<div class="post-metadata">

**Author:** ![lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lee](https://www.ruby-forum.com/u/lee)\
**Post date:** [April 25, 2009, 1:42am UTC](https://www.ruby-forum.com/t/rake-gems-not-working-in-test-environment/166298/4 "2009-04-25T01:42:39Z")

</div>

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

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/e87b901813a541a5?hl=en](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/e87b901813a541a5?hl=en)

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).

However, I’m surprised that “require ‘list’” _ever_ worked. Even with  
the Rails environment loaded, it gives me an error. The correct  
require would be ‘active\_record/acts/list’.

On a somewhat related note, I’ve found that Rake tasks work a lot  
better than standalone Ruby programs, and save a lot of headaches with  
loading the environment…

–Matt J.
