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)
精彩评论