Forum: Ruby require_relative doesn't work for nested includes

0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2014-08-16 15:33
(Crossposting note: I've also posted this question at
http://stackoverflow.com/questions/25487797/ruby-a...)

I am writing rspec tests. Some of the classes I'm testing are located in
a directory, which I would prefer by specifying a relative path. I
therefore wrote something like this:

   # Location of the class files relative to the rspec directory
   PICKER_DIR='../../.....'

   # Load a class file
   require_relative PICKER_DIR+'/pickercomposer.rb'

Now, the problem is that pickercomposer.rb itself uses a

  require 'picker.rb' # Assumed to be in the same directory as
pickercomposer.rb

and assumes that RUBYLIB has been set accordingly. If pickercomposer.rb
would do a

  require_relative 'picker.rb'

everything would be fine, but pickercomposer.rb was written (and is
still used) occasionally with Ruby 1.8.7, which did not have a
require_relative function.

What is the best workaround? Do I need to setup RUBYLIB, before
executing my rspec test, or is there a neat way to achive the goal from
inside the rspec file?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.