From: Gavin Sinclair Date: 2005-10-23T14:47:01+09:00 Subject: Re: Find the test dir Gavin Sinclair wrote: > > paths = File.expand_path(File.dirname(__FILE__)).split('/') > > paths.size.downto(1) do |i| > > f = (paths.slice(0..i)+['test']).join('/') > > $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f) > > end > > raise unless $TESTDIR > > [...] > > However, I would use the 'pathname' library to clarify some of the > code. To wit (untested): require 'pathname' def find_test_dir dir = Pathname.new(__FILE__) loop do dir = dir.dirname test_dir = dir + "test" return test_dir if test_dir.directory? raise "Test directory not found" if dir.mountpoint? end end # ... fixture = find_test_dir() + "FIXTURE" Cheers, Gavin