开发者

Rails 3: How to include files from "lib" directory when running tests?

When I run:

ruby -I test test/unit/job_test.rb

开发者_开发技巧from the application root directory, I got the following error:

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

Here is the relevant code:

# 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

It looks like when running tests, the files from the lib directory are not loaded automatically.

Any suggestions ?


Try putting this in your application.rb

config.autoload_paths += %W(#{config.root}/lib)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜