Watir $LOAD_PATH for test cases

Bret on Watir Mailing List

Actually, the best way to do this is to put test root in your load path.
$LOAD_PATH << File.dirname(__FILE__) + ‘/../’ require ‘lib/variables’ 

The problem with Keith’s solution is that you’ll end up requiring the same file from different tests via different paths. The semantics of require is that it won’t load a library if it has already been loaded, but if you are loading the same file but using a different path in your require statement, require will think it is a different library and load it again.

I am wondering if a better thing would be to unshift the path so it’s first in the stack like this:

$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')require ‘lib/variables’

Would it be a bit better? Would it cause problems if you are use other require for ‘test/unit’ etc…? Ideas?

close Reblog this comment
blog comments powered by Disqus