弃用警告模拟不会自动添加到加载路径

时间:2010-12-08 16:24:28

标签: ruby-on-rails

升级到Rails 3后,我收到了这个弃用警告:

DEPRECATION WARNING: "Rails.root/test/mocks/test" won't be added automatically to load paths anymore in future releases.

那么如何在Rails 3中实现呢?

1 个答案:

答案 0 :(得分:1)

Rails只检查mocks / test目录是否存在,如果存在则发出警告。以下是来自rails / railties / lib / rails / application / configuration.rb的代码:

if File.exists?("#{root}/test/mocks/#{Rails.env}")
        ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " <<
          "automatically to load paths anymore in future releases"
        paths.mocks_path  "test/mocks", :load_path => true, :glob => Rails.env
      end

所以看起来这条消息会一直存在,直到他们弃用它为止。

如果您将来在加载路径中需要此路径,我认为您只需在config / application.rb中执行类似的操作(请注意直接从config / application.rb模板中获取的注释):

# Add additional load paths for your own custom dirs
config.load_paths += %W( #{config.root}/test/mocks/#{Rails.env} )

我没试过,但这应该有帮助!