Skip to content
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.

Example:

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

  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 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
View
7 spec/ruby/core/kernel/shared/require.rb
@@ -173,6 +173,13 @@
ScratchPad.recorded.should == [:loaded]
end
+ it "does not load file twice after $LOAD_PATH change" do
+ $LOAD_PATH << CODE_LOADING_DIR
+ @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
$LOAD_PATH << CODE_LOADING_DIR
lambda do
View
1 spec/ruby/fixtures/code/gem/load_fixture.rb
@@ -0,0 +1 @@
+ScratchPad << :loaded

0 comments on commit db572b0

Please sign in to comment.
Something went wrong with that request. Please try again.