Unable to require 'test/unit'

Hi All

I am having the following error when I try to require ‘test/unit’, on
Mac OS X using rbenv with rub 1.9.3, has anyone seen this error before ?
if so can you tell me how to fix it.

Thanks

/ruby_sandbox/ruby_best_practice/unit_test_experiment$> ruby
test_experiment01.rb

/Users/mxruby/.rbenv/versions/1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': cannot load such file -- experiment01 (LoadError) from /Users/mxruby/.rbenv/versions/1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’
from test_experiment01.rb:3:in `’

On Aug 4, 2012, at 10:35 , Ja Tse [email protected] wrote:

`require’: cannot load such file – experiment01 (LoadError)
No, you have an error when you try to require ‘experiment01’, not
‘test/unit’. Look at your load path.

Am 04.08.2012 19:35, schrieb Ja Tse:

/Users/mxruby/.rbenv/versions/1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in

`require’: cannot load such file – experiment01 (LoadError)
from

/Users/mxruby/.rbenv/versions/1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in

require' from test_experiment01.rb:3:in

maybe you used require ‘experiment01’
instead of require_relative ‘experiment01’?

On 6/08/2012, at 6:53 AM, Ja Tse wrote:

It works with “require_relative ‘experiment01’”, but I am sure why it
didn’t work with just require.

Ruby looks for files in a list of directories called $LOAD_PATH. If your
file isn’t in one of these directories ‘require’ won’t find it. If you
puts $LOAD_PATH you can see the list of directories.

Henry

It works with “require_relative ‘experiment01’”, but I am sure why it
didn’t work with just require.

Am 05.08.2012 20:53, schrieb Ja Tse:

It works with “require_relative ‘experiment01’”, but I am sure why it
didn’t work with just require.

In case you just switched from 1.8 to 1.9:
The behaviour of require changed in 1.9.2, since the path of
the requiring file is no longer included in the $LOAD_PATH.

Thus, to require a file in the same directory,
you need to e.g. use either

require ‘./myfile’

or

require_relative ‘myfile’

See also
http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-require

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs