Watir $LOAD_PATH for test cases
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?
Comments (1) to “Watir $LOAD_PATH for test cases”
Post a Comment
You must be logged in to post a comment.
bret wrote:
I also use unshift sometimes. It is necessary when there is more than one version of the library in the load path and you want yours to be the one used.
Posted on 24-Nov-07 at 1:36 pm | Permalink