Search code examples
rubyrakeminitest

Rake::TestTask default libs not requiring my ./lib folder


I'm working in a simple Rack app trying to update some models with unit tests. I added a rake:TestTask.new task:

Rake::TestTask.new do |t|
  t.test_files = FileList['test/*_test.rb']
  t.verbose = true
end

t.libs by default specifies only ['lib'], so i expect this to automatically require my local ./lib directory... but it doesn't. is this meant to refer to system libraries instead? as a workaround i'm doing my requiring though test_helper.rb with Dir[File.expand_path('../lib/**/*.rb', File.dirname(__FILE__))].each { |file| require file } but unless there is a reason not to I'd prefer to require all my libraries once than at the top of each test file.


Solution

  • TestTask will add lib to the load path, but it does not actually load the files. Your tests should require the code needed to run.