mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@875a09e
This commit is contained in:
parent
a06301b103
commit
5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions
|
@ -19,7 +19,7 @@ describe "C-API Kernel function" do
|
|||
|
||||
describe "rb_need_block" do
|
||||
it "raises a LocalJumpError if no block is given" do
|
||||
lambda { @s.rb_need_block }.should raise_error(LocalJumpError)
|
||||
-> { @s.rb_need_block }.should raise_error(LocalJumpError)
|
||||
end
|
||||
|
||||
it "does not raise a LocalJumpError if a block is given" do
|
||||
|
@ -64,12 +64,12 @@ describe "C-API Kernel function" do
|
|||
|
||||
describe "rb_raise" do
|
||||
it "raises an exception" do
|
||||
lambda { @s.rb_raise({}) }.should raise_error(TypeError)
|
||||
-> { @s.rb_raise({}) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "terminates the function at the point it was called" do
|
||||
h = {}
|
||||
lambda { @s.rb_raise(h) }.should raise_error(TypeError)
|
||||
-> { @s.rb_raise(h) }.should raise_error(TypeError)
|
||||
h[:stage].should == :before
|
||||
end
|
||||
end
|
||||
|
@ -95,7 +95,7 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError if there is no catch block for the symbol" do
|
||||
lambda { @s.rb_throw(nil) }.should raise_error(ArgumentError)
|
||||
-> { @s.rb_throw(nil) }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -121,7 +121,7 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError if there is no catch block for the symbol" do
|
||||
lambda { @s.rb_throw(nil) }.should raise_error(ArgumentError)
|
||||
-> { @s.rb_throw(nil) }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -151,13 +151,13 @@ describe "C-API Kernel function" do
|
|||
|
||||
describe "rb_sys_fail" do
|
||||
it "raises an exception from the value of errno" do
|
||||
lambda do
|
||||
-> do
|
||||
@s.rb_sys_fail("additional info")
|
||||
end.should raise_error(SystemCallError, /additional info/)
|
||||
end
|
||||
|
||||
it "can take a NULL message" do
|
||||
lambda do
|
||||
-> do
|
||||
@s.rb_sys_fail(nil)
|
||||
end.should raise_error(Errno::EPERM)
|
||||
end
|
||||
|
@ -165,13 +165,13 @@ describe "C-API Kernel function" do
|
|||
|
||||
describe "rb_syserr_fail" do
|
||||
it "raises an exception from the given error" do
|
||||
lambda do
|
||||
-> do
|
||||
@s.rb_syserr_fail(Errno::EINVAL::Errno, "additional info")
|
||||
end.should raise_error(Errno::EINVAL, /additional info/)
|
||||
end
|
||||
|
||||
it "can take a NULL message" do
|
||||
lambda do
|
||||
-> do
|
||||
@s.rb_syserr_fail(Errno::EINVAL::Errno, nil)
|
||||
end.should raise_error(Errno::EINVAL)
|
||||
end
|
||||
|
@ -189,7 +189,7 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises LocalJumpError when no block is given" do
|
||||
lambda { @s.rb_yield(1) }.should raise_error(LocalJumpError)
|
||||
-> { @s.rb_yield(1) }.should raise_error(LocalJumpError)
|
||||
end
|
||||
|
||||
it "rb_yield to a block that breaks does not raise an error" do
|
||||
|
@ -229,7 +229,7 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises LocalJumpError when no block is given" do
|
||||
lambda { @s.rb_yield_splat([1, 2]) }.should raise_error(LocalJumpError)
|
||||
-> { @s.rb_yield_splat([1, 2]) }.should raise_error(LocalJumpError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -249,7 +249,7 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises LocalJumpError when no block is given" do
|
||||
lambda { @s.rb_yield_splat([1, 2]) }.should raise_error(LocalJumpError)
|
||||
-> { @s.rb_yield_splat([1, 2]) }.should raise_error(LocalJumpError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -276,7 +276,7 @@ describe "C-API Kernel function" do
|
|||
|
||||
it "will allow cleanup code to run after a raise" do
|
||||
proof = [] # Hold proof of work performed after the yield.
|
||||
lambda do
|
||||
-> do
|
||||
@s.rb_protect_yield(7, proof) { |x| raise NameError}
|
||||
end.should raise_error(NameError)
|
||||
proof[0].should == 23
|
||||
|
@ -284,7 +284,7 @@ describe "C-API Kernel function" do
|
|||
|
||||
it "will return nil if an error was raised" do
|
||||
proof = [] # Hold proof of work performed after the yield.
|
||||
lambda do
|
||||
-> do
|
||||
@s.rb_protect_yield(7, proof) { |x| raise NameError}
|
||||
end.should raise_error(NameError)
|
||||
proof[0].should == 23
|
||||
|
@ -301,7 +301,7 @@ describe "C-API Kernel function" do
|
|||
|
||||
it "will allow cleanup code to be run when an exception is raised" do
|
||||
proof = []
|
||||
lambda do
|
||||
-> do
|
||||
@s.rb_eval_string_protect('raise RuntimeError', proof)
|
||||
end.should raise_error(RuntimeError)
|
||||
proof.should == [23, nil]
|
||||
|
@ -310,12 +310,12 @@ describe "C-API Kernel function" do
|
|||
|
||||
describe "rb_rescue" do
|
||||
before :each do
|
||||
@proc = lambda { |x| x }
|
||||
@raise_proc_returns_sentinel = lambda {|*_| :raise_proc_executed }
|
||||
@raise_proc_returns_arg = lambda {|*a| a }
|
||||
@arg_error_proc = lambda { |*_| raise ArgumentError, '' }
|
||||
@std_error_proc = lambda { |*_| raise StandardError, '' }
|
||||
@exc_error_proc = lambda { |*_| raise Exception, '' }
|
||||
@proc = -> x { x }
|
||||
@raise_proc_returns_sentinel = -> *_ { :raise_proc_executed }
|
||||
@raise_proc_returns_arg = -> *a { a }
|
||||
@arg_error_proc = -> *_ { raise ArgumentError, '' }
|
||||
@std_error_proc = -> *_ { raise StandardError, '' }
|
||||
@exc_error_proc = -> *_ { raise Exception, '' }
|
||||
end
|
||||
|
||||
it "executes passed function" do
|
||||
|
@ -344,21 +344,21 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises an exception if passed function raises an exception other than StandardError" do
|
||||
lambda { @s.rb_rescue(@exc_error_proc, nil, @raise_proc_returns_arg, nil) }.should raise_error(Exception)
|
||||
-> { @s.rb_rescue(@exc_error_proc, nil, @raise_proc_returns_arg, nil) }.should raise_error(Exception)
|
||||
end
|
||||
|
||||
it "raises an exception if any exception is raised inside 'raise function'" do
|
||||
lambda { @s.rb_rescue(@std_error_proc, nil, @std_error_proc, nil) }.should raise_error(StandardError)
|
||||
-> { @s.rb_rescue(@std_error_proc, nil, @std_error_proc, nil) }.should raise_error(StandardError)
|
||||
end
|
||||
|
||||
it "makes $! available only during 'raise function' execution" do
|
||||
@s.rb_rescue(@std_error_proc, nil, lambda { |*_| $! }, nil).class.should == StandardError
|
||||
@s.rb_rescue(@std_error_proc, nil, -> *_ { $! }, nil).class.should == StandardError
|
||||
$!.should == nil
|
||||
end
|
||||
|
||||
it "returns the break value if the passed function yields to a block with a break" do
|
||||
def proc_caller
|
||||
@s.rb_rescue(lambda { |*_| yield }, nil, @proc, nil)
|
||||
@s.rb_rescue(-> *_ { yield }, nil, @proc, nil)
|
||||
end
|
||||
|
||||
proc_caller { break :value }.should == :value
|
||||
|
@ -367,13 +367,13 @@ describe "C-API Kernel function" do
|
|||
|
||||
describe "rb_rescue2" do
|
||||
it "only rescues if one of the passed exceptions is raised" do
|
||||
proc = lambda { |x| x }
|
||||
arg_error_proc = lambda { |*_| raise ArgumentError, '' }
|
||||
run_error_proc = lambda { |*_| raise RuntimeError, '' }
|
||||
type_error_proc = lambda { |*_| raise TypeError, '' }
|
||||
proc = -> x { x }
|
||||
arg_error_proc = -> *_ { raise ArgumentError, '' }
|
||||
run_error_proc = -> *_ { raise RuntimeError, '' }
|
||||
type_error_proc = -> *_ { raise TypeError, '' }
|
||||
@s.rb_rescue2(arg_error_proc, :no_exc, proc, :exc, ArgumentError, RuntimeError).should == :exc
|
||||
@s.rb_rescue2(run_error_proc, :no_exc, proc, :exc, ArgumentError, RuntimeError).should == :exc
|
||||
lambda {
|
||||
-> {
|
||||
@s.rb_rescue2(type_error_proc, :no_exc, proc, :exc, ArgumentError, RuntimeError)
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
|
@ -385,11 +385,11 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "executes passed function" do
|
||||
@s.rb_catch("foo", lambda { 1 }).should == 1
|
||||
@s.rb_catch("foo", -> { 1 }).should == 1
|
||||
end
|
||||
|
||||
it "terminates the function at the point it was called" do
|
||||
proc = lambda do
|
||||
proc = -> do
|
||||
ScratchPad << :before_throw
|
||||
throw :thrown_value
|
||||
ScratchPad << :after_throw
|
||||
|
@ -399,7 +399,7 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError if the throw symbol isn't caught" do
|
||||
lambda { @s.rb_catch("foo", lambda { throw :bar }) }.should raise_error(ArgumentError)
|
||||
-> { @s.rb_catch("foo", -> { throw :bar }) }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -411,11 +411,11 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "executes passed function" do
|
||||
@s.rb_catch_obj(@tag, lambda { 1 }).should == 1
|
||||
@s.rb_catch_obj(@tag, -> { 1 }).should == 1
|
||||
end
|
||||
|
||||
it "terminates the function at the point it was called" do
|
||||
proc = lambda do
|
||||
proc = -> do
|
||||
ScratchPad << :before_throw
|
||||
throw @tag
|
||||
ScratchPad << :after_throw
|
||||
|
@ -425,36 +425,36 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError if the throw symbol isn't caught" do
|
||||
lambda { @s.rb_catch("foo", lambda { throw :bar }) }.should raise_error(ArgumentError)
|
||||
-> { @s.rb_catch("foo", -> { throw :bar }) }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_ensure" do
|
||||
it "executes passed function and returns its value" do
|
||||
proc = lambda { |x| x }
|
||||
proc = -> x { x }
|
||||
@s.rb_ensure(proc, :proc, proc, :ensure_proc).should == :proc
|
||||
end
|
||||
|
||||
it "executes passed 'ensure function' when no exception is raised" do
|
||||
foo = nil
|
||||
proc = lambda { |*_| }
|
||||
ensure_proc = lambda { |x| foo = x }
|
||||
proc = -> *_ { }
|
||||
ensure_proc = -> x { foo = x }
|
||||
@s.rb_ensure(proc, nil, ensure_proc, :foo)
|
||||
foo.should == :foo
|
||||
end
|
||||
|
||||
it "executes passed 'ensure function' when an exception is raised" do
|
||||
foo = nil
|
||||
raise_proc = lambda { raise '' }
|
||||
ensure_proc = lambda { |x| foo = x }
|
||||
raise_proc = -> { raise '' }
|
||||
ensure_proc = -> x { foo = x }
|
||||
@s.rb_ensure(raise_proc, nil, ensure_proc, :foo) rescue nil
|
||||
foo.should == :foo
|
||||
end
|
||||
|
||||
it "raises the same exception raised inside passed function" do
|
||||
raise_proc = lambda { |*_| raise RuntimeError, 'foo' }
|
||||
proc = lambda { |*_| }
|
||||
lambda { @s.rb_ensure(raise_proc, nil, proc, nil) }.should raise_error(RuntimeError, 'foo')
|
||||
raise_proc = -> *_ { raise RuntimeError, 'foo' }
|
||||
proc = -> *_ { }
|
||||
-> { @s.rb_ensure(raise_proc, nil, proc, nil) }.should raise_error(RuntimeError, 'foo')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -466,7 +466,7 @@ describe "C-API Kernel function" do
|
|||
|
||||
describe "rb_block_proc" do
|
||||
it "converts the implicit block into a proc" do
|
||||
proc = @s.rb_block_proc() { 1+1 }
|
||||
proc = @s.rb_block_proc { 1+1 }
|
||||
proc.should be_kind_of(Proc)
|
||||
proc.call.should == 2
|
||||
proc.lambda?.should == false
|
||||
|
@ -482,16 +482,16 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
describe "rb_block_lambda" do
|
||||
it "converts the implicit block into a Proc but does not convert it to a lambda" do
|
||||
proc = @s.rb_block_proc { 1+1 }
|
||||
it "converts the implicit block into a lambda" do
|
||||
proc = @s.rb_block_lambda { 1+1 }
|
||||
proc.should be_kind_of(Proc)
|
||||
proc.call.should == 2
|
||||
proc.lambda?.should == false
|
||||
proc.lambda?.should == true
|
||||
end
|
||||
|
||||
it "passes through an existing Proc and does not convert to a lambda" do
|
||||
b = proc { 1+1 }
|
||||
proc = @s.rb_block_proc(&b)
|
||||
proc = @s.rb_block_lambda(&b)
|
||||
proc.should equal(b)
|
||||
proc.call.should == 2
|
||||
proc.lambda?.should == false
|
||||
|
@ -569,7 +569,7 @@ describe "C-API Kernel function" do
|
|||
@s.rb_funcall3(@obj, :method_public).should == :method_public
|
||||
end
|
||||
it "does not call a private method" do
|
||||
lambda { @s.rb_funcall3(@obj, :method_private) }.should raise_error(NoMethodError, /private/)
|
||||
-> { @s.rb_funcall3(@obj, :method_private) }.should raise_error(NoMethodError, /private/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -588,7 +588,7 @@ describe "C-API Kernel function" do
|
|||
end
|
||||
|
||||
it "does not call a private method" do
|
||||
lambda { @s.rb_funcall_with_block(@obj, :method_private, proc { :result }) }.should raise_error(NoMethodError, /private/)
|
||||
-> { @s.rb_funcall_with_block(@obj, :method_private, proc { :result }) }.should raise_error(NoMethodError, /private/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue