Permalink
Browse files

Spec that #require and #require_relative keep symlinks for $LOADED_FE…

…ATURES and __FILE__
  • Loading branch information...
eregon committed Jul 7, 2018
1 parent b4ef552 commit 569b1d83ba1dd57a4d70f6bc2974f0866b25102a
@@ -199,6 +199,46 @@
$LOADED_FEATURES.should include(@abs_path)
end
platform_is_not :windows do
describe "with symlinks" do
before :each do
@symlink_to_code_dir = tmp("codesymlink")
File.symlink(CODE_LOADING_DIR, @symlink_to_code_dir)
@symlink_basename = File.basename(@symlink_to_code_dir)
@requiring_file = tmp("requiring")
end
after :each do
rm_r @symlink_to_code_dir, @requiring_file
end
it "does not canonicalize the path and stores a path with symlinks" do
symlink_path = "#{@symlink_basename}/load_fixture.rb"
absolute_path = "#{tmp("")}#{symlink_path}"
canonical_path = "#{CODE_LOADING_DIR}/load_fixture.rb"
touch(@requiring_file) { |f|
f.puts "require_relative #{symlink_path.inspect}"
}
load(@requiring_file)
ScratchPad.recorded.should == [:loaded]
features = $LOADED_FEATURES.select { |path| path.end_with?('load_fixture.rb') }
features.should include(absolute_path)
features.should_not include(canonical_path)
end
it "stores the same path that __FILE__ returns in the required file" do
symlink_path = "#{@symlink_basename}/load_fixture_and__FILE__.rb"
touch(@requiring_file) { |f|
f.puts "require_relative #{symlink_path.inspect}"
}
load(@requiring_file)
loaded_feature = $LOADED_FEATURES.last
ScratchPad.recorded.should == [loaded_feature]
end
end
end
it "does not store the path if the load fails" do
saved_loaded_features = $LOADED_FEATURES.dup
lambda { require_relative("#{@dir}/raise_fixture.rb") }.should raise_error(RuntimeError)
@@ -17,7 +17,6 @@
end
it_behaves_like :kernel_require_basic, :require, CodeLoadingSpecs::Method.new
it_behaves_like :kernel_require, :require, CodeLoadingSpecs::Method.new
end
@@ -31,6 +30,5 @@
end
it_behaves_like :kernel_require_basic, :require, Kernel
it_behaves_like :kernel_require, :require, Kernel
end
@@ -305,6 +305,40 @@
$LOADED_FEATURES.should include(@path)
end
platform_is_not :windows do
describe "with symlinks" do
before :each do
@symlink_to_code_dir = tmp("codesymlink")
File.symlink(CODE_LOADING_DIR, @symlink_to_code_dir)
$LOAD_PATH.delete(CODE_LOADING_DIR)
$LOAD_PATH.unshift(@symlink_to_code_dir)
end
after :each do
rm_r @symlink_to_code_dir
end
it "does not canonicalize the path and stores a path with symlinks" do
symlink_path = "#{@symlink_to_code_dir}/load_fixture.rb"
canonical_path = "#{CODE_LOADING_DIR}/load_fixture.rb"
@object.require(symlink_path).should be_true
ScratchPad.recorded.should == [:loaded]
features = $LOADED_FEATURES.select { |path| path.end_with?('load_fixture.rb') }
features.should include(symlink_path)
features.should_not include(canonical_path)
end
it "stores the same path that __FILE__ returns in the required file" do
symlink_path = "#{@symlink_to_code_dir}/load_fixture_and__FILE__.rb"
@object.require(symlink_path).should be_true
loaded_feature = $LOADED_FEATURES.last
ScratchPad.recorded.should == [loaded_feature]
end
end
end
it "does not store the path if the load fails" do
$LOAD_PATH << CODE_LOADING_DIR
saved_loaded_features = $LOADED_FEATURES.dup
@@ -0,0 +1 @@
ScratchPad << __FILE__

0 comments on commit 569b1d8

Please sign in to comment.