git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-06-29 14:35:37 +00:00
parent 6a4aa4838c
commit 5b593e3889
79 changed files with 1555 additions and 304 deletions

View file

@ -49,8 +49,7 @@ describe "Kernel#autoload" do
end
it "can autoload in instance_eval" do
instance_eval do
# this instance_eval is not needed because specs are run in instance_eval
Object.new.instance_eval do
autoload :KSAutoloadD, fixture(__FILE__, "autoload_d.rb")
KSAutoloadD.loaded.should == :ksautoload_d
end

View file

@ -22,6 +22,12 @@ describe 'Kernel#caller' do
locations.length.should == 1
end
it 'returns an Array of caller locations using a range' do
locations = KernelSpecs::CallerTest.locations(1..1)
locations.length.should == 1
end
it 'returns the locations as String instances' do
locations = KernelSpecs::CallerTest.locations
line = __LINE__ - 1

View file

@ -53,7 +53,7 @@ with_feature :encoding do
it "removes the final carriage return, newline from a multi-byte $_" do
script = fixture __FILE__, "#{@method}.rb"
KernelSpecs.encoded_chomp(script).should == "あれ"
KernelSpecs.run_with_dash_n(script).should == "あれ"
end
end

View file

@ -41,7 +41,7 @@ with_feature :encoding do
it "removes the final multi-byte character from $_" do
script = fixture __FILE__, "#{@method}.rb"
KernelSpecs.encoded_chop(script).should == ""
KernelSpecs.run_with_dash_n(script).should == ""
end
end

View file

@ -37,6 +37,16 @@ describe "Kernel#clone" do
o3.frozen?.should == true
end
ruby_version_is '2.4' do
it 'takes an option to copy freeze state or not' do
@obj.clone(freeze: true).frozen?.should == false
@obj.clone(freeze: false).frozen?.should == false
@obj.freeze
@obj.clone(freeze: true).frozen?.should == true
@obj.clone(freeze: false).frozen?.should == false
end
end
it "copies instance variables" do
clone = @obj.clone
clone.one.should == 1

View file

@ -32,26 +32,36 @@ module KernelSpecs
end
def self.has_private_method(name)
cmd = %[| #{ruby_cmd(nil)} -n -e "print Kernel.private_method_defined?('#{name}')"]
ruby_exe("puts", args: cmd) == "true"
IO.popen([*ruby_exe, "-n", "-e", "print Kernel.private_method_defined?(#{name.inspect})"], "r+") do |io|
io.puts
io.close_write
io.read
end == "true"
end
def self.chop(str, method)
cmd = "| #{ruby_cmd(nil)} -n -e '$_ = #{str.inspect}; #{method}; print $_'"
ruby_exe "puts", args: cmd
end
def self.encoded_chop(file)
ruby_exe "puts", args: "| #{ruby_cmd(nil)} -n #{file}"
IO.popen([*ruby_exe, "-n", "-e", "$_ = #{str.inspect}; #{method}; print $_"], "r+") do |io|
io.puts
io.close_write
io.read
end
end
def self.chomp(str, method, sep="\n")
cmd = "| #{ruby_cmd(nil)} -n -e '$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_'"
ruby_exe "puts", args: cmd
code = "$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_"
IO.popen([*ruby_exe, "-n", "-e", code], "r+") do |io|
io.puts
io.close_write
io.read
end
end
def self.encoded_chomp(file)
ruby_exe "puts", args: "| #{ruby_cmd(nil)} -n #{file}"
def self.run_with_dash_n(file)
IO.popen([*ruby_exe, "-n", file], "r+") do |io|
io.puts
io.close_write
io.read
end
end
# kind_of?, is_a?, instance_of?

View file

@ -18,9 +18,9 @@ describe "Kernel#public_method" do
it "raises a NameError when called on a protected method" do
@obj.send(:protected_method).should == :protected_method
lambda do
lambda {
@obj.public_method(:protected_method)
end.should raise_error(NameError)
}.should raise_error(NameError)
end
it "raises a NameError if we only repond_to_missing? method, true" do

View file

@ -0,0 +1,41 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Kernel#singleton_method" do
it "find a method defined on the singleton class" do
obj = Object.new
def obj.foo; end
obj.singleton_method(:foo).should be_an_instance_of(Method)
end
it "returns a Method which can be called" do
obj = Object.new
def obj.foo; 42; end
obj.singleton_method(:foo).call.should == 42
end
it "only looks at singleton methods and not at methods in the class" do
klass = Class.new do
def foo
42
end
end
obj = klass.new
obj.foo.should == 42
-> {
obj.singleton_method(:foo)
}.should raise_error(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
it "raises a NameError if there is no such method" do
obj = Object.new
-> {
obj.singleton_method(:not_existing)
}.should raise_error(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
end