-
Website
http://avdi.org/devblog -
Original page
http://avdi.org/devblog/2009/10/22/double-load-guards-in-ruby/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
bryanl
5 comments · 3 points
-
David Recordon
1 comment · 4 points
-
gambling
3 comments · 2 points
-
'n ddrylliog
4 comments · 1 points
-
joegrossberg
2 comments · 2 points
-
-
Popular Threads
-
RightAWS and SSL Certificates
3 weeks ago · 3 comments
-
Debugging Rule 1: It’s your fault
2 weeks ago · 1 comment
-
RightAWS and SSL Certificates
However, there are always a few files where relative requires can't be avoided. For instance, it is conventional to set up unit test/spec files so that they can be run standalone. In order for this to work each test file has to start out by requiring a test_helper.rb or a spec_helper.rb which then sets up $LOAD_PATH, requires additional libraries, etc. Because this test helper is the first thing to be loaded and can't rely on anything else to be configured, it has to be loaded with a relative path.
This is where I see the most double-loads occurring, because when all of the tests are run together they each require the test helper file, often with differing relative paths. Using expand_path is a way to ensure that files that must loaded relatively are required in a consistent way.
I may update the post to make it clear that I'm not suggesting you use relative requires throughout a project.