From: Brian Candler Date: 2010-09-27T23:08:36+09:00 Subject: Re: testing and requiring Iain Barnett wrote: > My point is, should I be using relative paths to these files from the > test file (or rake file, or wherever), or is there a better way to > require the files? The idiomatic way seems to use lib/appname.rb to do > this for running the app, what about for tests? Idiomatically, you set up the $LOAD_PATH appropriately for each test. You could run your tests individually from the command line like this: # cd to top directory ruby -Ilib t/class1.t (where t/class1.t contains "require 'appname/class1'" at the top of course) If you don't like having to specify -Ilib when running individual tests, then the solution is some variant of the following. Put a file called "boot.rb" at the top level of your project, which contains $:.unshift File.expand_path("#{File.dirname(__FILE__)}/lib") Then at the top of each t/foo.t file put: require "#{File.dirname(__FILE__)}/../boot" You can use this in bin/foo as well. By using this file for each point where your app starts, you should only ever have to require 'appname' or require 'appname/class1', never require 'lib/appname' If this file is *only* for supporting tests, not shared with any other part of your app, then you might want to put it inside the t/ directory instead, and adjust the requires appropriately. HTH, Brian. -- Posted via http://www.ruby-forum.com/.