Browse files

Add spec for require after $LOAD_PATH change

When developer add something to $LOAD_PATH and require once again the
same file ruby should not require it once again.


Rubinius have lib/racc/parser.rb file. And this file will require after

  require 'racc/parser'

After require 'rubygems' $LOAD_PATH will change and now we have access
to two version on 'racc/parser' (from Rubinius /lib and /gems/racc).
When user try to require once again rubinius will search via $LOAD_PATH
and hit racc/parser from _RUBYGEMS_. In ruby 1.9 mode all paths are
expanded so rubinius will require once again 'racc/parser'. This is
because in $LOADED_FEATURES we can find only
"[rubinius_path]/lib/racc/parser.rb". When CodeLoader will find file in
$LOAD_PATH ([rubygems]/racc/parser.rb) and full path is not part of
$LOADED_FEATURES this file will be load once again.
  • Loading branch information...
1 parent 149a364 commit db572b0bfb5b6fd5387379443e48cb40b613907d @LTe LTe committed Aug 31, 2012
Showing with 8 additions and 0 deletions.
  1. +7 −0 spec/ruby/core/kernel/shared/require.rb
  2. +1 −0 spec/ruby/fixtures/code/gem/load_fixture.rb
@@ -173,6 +173,13 @@
ScratchPad.recorded.should == [:loaded]
+ it "does not load file twice after $LOAD_PATH change" do
+ @object.send(@method, "load_fixture.rb").should be_true
+ $LOAD_PATH.unshift CODE_LOADING_DIR + "/gem"
+ @object.send(@method, "load_fixture.rb").should be_false
+ end
it "does not resolve a ./ relative path against $LOAD_PATH entries" do
lambda do
@@ -0,0 +1 @@
+ScratchPad << :loaded

0 comments on commit db572b0

Please sign in to comment.