mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@9be7c7e
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
aeeaadaad0
commit
b53cf149ad
246 changed files with 9108 additions and 548 deletions
|
@ -5,6 +5,13 @@ describe "Kernel#__dir__" do
|
|||
__dir__.should == File.realpath(File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
context "when used in eval with a given filename" do
|
||||
it "returns File.dirname(filename)" do
|
||||
eval("__dir__", nil, "foo.rb").should == "."
|
||||
eval("__dir__", nil, "foo/bar.rb").should == "foo"
|
||||
end
|
||||
end
|
||||
|
||||
context "when used in eval with top level binding" do
|
||||
it "returns the real name of the directory containing the currently-executing file" do
|
||||
eval("__dir__", binding).should == File.realpath(File.dirname(__FILE__))
|
||||
|
|
|
@ -7,7 +7,7 @@ require_relative 'fixtures/classes'
|
|||
|
||||
autoload :KSAutoloadA, "autoload_a.rb"
|
||||
autoload :KSAutoloadB, fixture(__FILE__, "autoload_b.rb")
|
||||
autoload :KSAutoloadC, fixture(__FILE__, "autoload_c.rb")
|
||||
autoload :KSAutoloadCallsRequire, "main_autoload_not_exist.rb"
|
||||
|
||||
def check_autoload(const)
|
||||
autoload? const
|
||||
|
@ -42,10 +42,11 @@ describe "Kernel#autoload" do
|
|||
KSAutoloadB.loaded.should == :ksautoload_b
|
||||
end
|
||||
|
||||
it "does not call Kernel.require or Kernel.load to load the file" do
|
||||
Kernel.should_not_receive(:require)
|
||||
Kernel.should_not_receive(:load)
|
||||
KSAutoloadC.loaded.should == :ksautoload_c
|
||||
it "calls main.require(path) to load the file" do
|
||||
main = TOPLEVEL_BINDING.eval("self")
|
||||
main.should_receive(:require).with("main_autoload_not_exist.rb")
|
||||
# The constant won't be defined since require is mocked to do nothing
|
||||
-> { KSAutoloadCallsRequire }.should raise_error(NameError)
|
||||
end
|
||||
|
||||
it "can autoload in instance_eval" do
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
module KSAutoloadC
|
||||
def self.loaded
|
||||
:ksautoload_c
|
||||
end
|
||||
end
|
|
@ -199,6 +199,46 @@ describe "Kernel#require_relative with a relative path" do
|
|||
$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 @@ describe "Kernel#require" do
|
|||
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 @@ describe "Kernel.require" do
|
|||
end
|
||||
|
||||
it_behaves_like :kernel_require_basic, :require, Kernel
|
||||
|
||||
it_behaves_like :kernel_require, :require, Kernel
|
||||
end
|
||||
|
|
|
@ -305,6 +305,80 @@ describe :kernel_require, shared: true do
|
|||
$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
|
||||
|
||||
describe "with symlinks in the required feature and $LOAD_PATH" do
|
||||
before :each do
|
||||
@dir = tmp("realdir")
|
||||
mkdir_p @dir
|
||||
@file = "#{@dir}/realfile.rb"
|
||||
touch(@file) { |f| f.puts 'ScratchPad << __FILE__' }
|
||||
|
||||
@symlink_to_dir = tmp("symdir").freeze
|
||||
File.symlink(@dir, @symlink_to_dir)
|
||||
@symlink_to_file = "#{@dir}/symfile.rb"
|
||||
File.symlink("realfile.rb", @symlink_to_file)
|
||||
end
|
||||
|
||||
after :each do
|
||||
rm_r @dir, @symlink_to_dir
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.4.4" do
|
||||
it "canonicalizes neither the entry in $LOAD_PATH nor the filename passed to #require" do
|
||||
$LOAD_PATH.unshift(@symlink_to_dir)
|
||||
@object.require("symfile").should be_true
|
||||
loaded_feature = "#{@symlink_to_dir}/symfile.rb"
|
||||
ScratchPad.recorded.should == [loaded_feature]
|
||||
$".last.should == loaded_feature
|
||||
$LOAD_PATH[0].should == @symlink_to_dir
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.4.4" do
|
||||
it "canonicalizes the entry in $LOAD_PATH but not the filename passed to #require" do
|
||||
$LOAD_PATH.unshift(@symlink_to_dir)
|
||||
@object.require("symfile").should be_true
|
||||
loaded_feature = "#{@dir}/symfile.rb"
|
||||
ScratchPad.recorded.should == [loaded_feature]
|
||||
$".last.should == loaded_feature
|
||||
$LOAD_PATH[0].should == @symlink_to_dir
|
||||
end
|
||||
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
|
||||
|
@ -417,7 +491,7 @@ describe :kernel_require, shared: true do
|
|||
$LOADED_FEATURES.should include(@path)
|
||||
end
|
||||
|
||||
it "canonicalizes non-unique absolute paths" do
|
||||
it "expands absolute paths containing .." do
|
||||
path = File.join CODE_LOADING_DIR, "..", "code", "load_fixture.rb"
|
||||
@object.require(path).should be_true
|
||||
$LOADED_FEATURES.should include(@path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue