当我跑步时:
ruby -I test test/unit/job_test.rb
从应用程序根目录,我收到以下错误:
.../app/models/name_position.rb:9:in `<class:NamePosition>':
uninitialized constant NamePosition::PositionManager (NameError)
from .../app/models/name_position.rb:1:in `<top (required)>'
from .../app/models/ac_buyer.rb:1:in `<top (required)>'
...
以下是相关代码:
# app/models/ac_buyer.rb
class AcBuyer < NamePosition
end
# app/models/name_position.rb
class NamePosition < ActiveRecord::Base
...
include PositionManager
end
# lib/position_manager.rb
module PositionManager
...
end
看起来在运行测试时,lib
目录中的文件不会自动加载。
有什么建议吗?
答案 0 :(得分:6)
尝试将其放入您的application.rb
config.autoload_paths += %W(#{config.root}/lib)