# Unit testing /lib directory

**URL:** <https://www.ruby-forum.com/t/unit-testing-lib-directory/181222>\
**Category:** Rails\
**Created:** [January 7, 2010, 3:06pm UTC](https://www.ruby-forum.com/t/unit-testing-lib-directory/181222 "2010-01-07T15:06:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pasalic\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@Pasalic\_Z](https://www.ruby-forum.com/u/Pasalic_Z)\
**Post date:** [January 7, 2010, 3:06pm UTC](https://www.ruby-forum.com/t/unit-testing-lib-directory/181222/1 "2010-01-07T15:06:44Z")

</div>

Hi

I’m writing small replacement for ActiveRecord to support columns  
oriented databases (HBase). I put all of my code into /lib folder and  
created small rake file into /lib/tasks to support unit testing:

#----- start of file -----  
namespace :test do  
Rake::TestTask.new(:lib) do |t|  
t.libs \<\< “lib”  
t.libs \<\< “test”  
t.pattern = ‘test/lib/\*\*/\*\_test.rb’  
t.verbose = true  
end  
Rake::Task[‘test:lib’].comment = “Run the tests in test/lib”  
end  
#---- end of file -------

Now i’m able to write unit tests in /test/lib.

My main problem is that my unit tests now do not see any rails loaded  
classes, e.g. one of my unit tests uses ActiveRecord::Errors but i’m  
getting :

“NameError: uninitialized constant ActiveRecord::Errors”

Do I need to include (require) all rails classes in my unit tests just  
to be sure that everything works fine? (in general I included rubygems  
and active\_record but still getting same error)? Any ideas,  
comments, …?

Thanks  
-Zaharije
