Rake gems not working in test environment


#1

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:inrequire’
/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:ingem_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:inrequire’
/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:inrequire’
/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:ingem_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:inrequire’
/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:inrequire’
/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:ingem_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:inrequire’
/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:inrequire’
/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:inrequire_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:inrequire_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:ineach’
/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:ineach’
/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:inprocess’
/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:inrun’
/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:inrequire’
/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:innew_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:incall’
/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:ineach’
/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:ininvoke_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:ininvoke_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:incall’
/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:ineach’
/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:ininvoke_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:ininvoke_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:ineach’
/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:ininvoke_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:ininvoke_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:ininvoke_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:ineach’
/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:instandard_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:inrun’
/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:inrun’
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/bin/rake:31
/usr/bin/rake:19:in `load’
/usr/bin/rake:19


#2

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.


#3

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.


#4

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

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.