views:

36

answers:

1

I understand the benefit of putting classes, modules, etc. in the lib folder in Rails, but I haven't been able to find a clean way of testing these files. For the most part, it seems like unit tests would be the logical approach.

I guess my question is: What is the "rails way" for testing lib files?

A: 

Your lib directory is not automatically loaded by rails.

You can use ActiveSupport::Dependencies to override const_missing. Basically rails will try to load your constants when it boots, if they are undefined or not in memory it will look at your load paths.

If you have a file like my_class.rb, rails expects it to be MyClass.

The beauty of this is if you have some stuff in your lib directory, you don't have to require it with a relative path you can just say require 'something', instead of require 'lib/something'.

Joseph Silvashy