Ruby - Is there a way to overwrite the __FILE__ variable?
Posted
by Markus Orrelly
on Stack Overflow
See other posts from Stack Overflow
or by Markus Orrelly
Published on 2010-03-16T19:02:30Z
Indexed on
2010/03/16
19:11 UTC
Read the original article
Hit count: 193
ruby
|global-variables
I'm doing some unit testing, and some of the code is checking to see if files exist based on the relative path of the currently-executing script by using the FILE variable. I'm doing something like this:
if File.directory?(File.join(File.dirname(__FILE__),'..','..','directory'))
blah blah blah ...
else
raise "Can't find directory"
end
I'm trying to find a way to make it fail in the unit tests without doing anything drastic. Being able to overwrite the __ FILE __ variable would be easiest, but as far as I can tell, it's impossible.
Any tips?
© Stack Overflow or respective owner