diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-07-27 12:40:09 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-07-27 12:40:09 +0200 |
commit | 5c276e1cc91c5ab2a41fbf7827af2fed914a2bc0 (patch) | |
tree | 05b5c68c8b2a00224d4646ea3b26ce3877efaadd /spec/ruby/optional | |
parent | a06301b103371b0b7da8eaca26ba744961769f99 (diff) |
Update to ruby/spec@875a09e
Diffstat (limited to 'spec/ruby/optional')
24 files changed, 220 insertions, 226 deletions
diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb index 56373efe34..acd225e0e0 100644 --- a/spec/ruby/optional/capi/array_spec.rb +++ b/spec/ruby/optional/capi/array_spec.rb @@ -8,7 +8,7 @@ describe :rb_ary_new2, shared: true do end it "raises an ArgumentError when the given argument is negative" do - lambda { @s.send(@method, -1) }.should raise_error(ArgumentError) + -> { @s.send(@method, -1) }.should raise_error(ArgumentError) end end @@ -84,7 +84,7 @@ describe "C-API Array function" do end it "raises a #{frozen_error_class} if the array is frozen" do - lambda { @s.rb_ary_cat([].freeze, 1) }.should raise_error(frozen_error_class) + -> { @s.rb_ary_cat([].freeze, 1) }.should raise_error(frozen_error_class) end end @@ -131,7 +131,7 @@ describe "C-API Array function" do end it "raises a #{frozen_error_class} if the array is frozen" do - lambda { @s.rb_ary_rotate([].freeze, 1) }.should raise_error(frozen_error_class) + -> { @s.rb_ary_rotate([].freeze, 1) }.should raise_error(frozen_error_class) end end @@ -205,7 +205,7 @@ describe "C-API Array function" do it "raises an IndexError if the negative index is greater than the length" do a = [1, 2, 3] - lambda { @s.rb_ary_store(a, -10, 5) }.should raise_error(IndexError) + -> { @s.rb_ary_store(a, -10, 5) }.should raise_error(IndexError) end it "enlarges the array as needed" do @@ -216,7 +216,7 @@ describe "C-API Array function" do it "raises a #{frozen_error_class} if the array is frozen" do a = [1, 2, 3].freeze - lambda { @s.rb_ary_store(a, 1, 5) }.should raise_error(frozen_error_class) + -> { @s.rb_ary_store(a, 1, 5) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/optional/capi/bignum_spec.rb b/spec/ruby/optional/capi/bignum_spec.rb index a5863519b6..b20275b8f7 100644 --- a/spec/ruby/optional/capi/bignum_spec.rb +++ b/spec/ruby/optional/capi/bignum_spec.rb @@ -33,8 +33,8 @@ describe "CApiBignumSpecs" do end it "raises RangeError if passed Bignum overflow long" do - lambda { @s.rb_big2long(ensure_bignum(@max_long + 1)) }.should raise_error(RangeError) - lambda { @s.rb_big2long(ensure_bignum(@min_long - 1)) }.should raise_error(RangeError) + -> { @s.rb_big2long(ensure_bignum(@max_long + 1)) }.should raise_error(RangeError) + -> { @s.rb_big2long(ensure_bignum(@min_long - 1)) }.should raise_error(RangeError) end end @@ -47,8 +47,8 @@ describe "CApiBignumSpecs" do end it "raises RangeError if passed Bignum overflow long" do - lambda { @s.rb_big2ll(ensure_bignum(@max_long << 40)) }.should raise_error(RangeError) - lambda { @s.rb_big2ll(ensure_bignum(@min_long << 40)) }.should raise_error(RangeError) + -> { @s.rb_big2ll(ensure_bignum(@max_long << 40)) }.should raise_error(RangeError) + -> { @s.rb_big2ll(ensure_bignum(@min_long << 40)) }.should raise_error(RangeError) end end @@ -65,8 +65,8 @@ describe "CApiBignumSpecs" do end it "raises RangeError if passed Bignum overflow long" do - lambda { @s.rb_big2ulong(ensure_bignum(@max_ulong + 1)) }.should raise_error(RangeError) - lambda { @s.rb_big2ulong(ensure_bignum(@min_long - 1)) }.should raise_error(RangeError) + -> { @s.rb_big2ulong(ensure_bignum(@max_ulong + 1)) }.should raise_error(RangeError) + -> { @s.rb_big2ulong(ensure_bignum(@min_long - 1)) }.should raise_error(RangeError) end end @@ -212,13 +212,13 @@ describe "CApiBignumSpecs" do it "raises FloatDomainError for Infinity values" do inf = 1.0 / 0 - lambda { @s.rb_dbl2big(inf) }.should raise_error(FloatDomainError) + -> { @s.rb_dbl2big(inf) }.should raise_error(FloatDomainError) end it "raises FloatDomainError for NaN values" do nan = 0.0 / 0 - lambda { @s.rb_dbl2big(nan) }.should raise_error(FloatDomainError) + -> { @s.rb_dbl2big(nan) }.should raise_error(FloatDomainError) end end end diff --git a/spec/ruby/optional/capi/class_spec.rb b/spec/ruby/optional/capi/class_spec.rb index 57636f3819..0b03fb9e6c 100644 --- a/spec/ruby/optional/capi/class_spec.rb +++ b/spec/ruby/optional/capi/class_spec.rb @@ -18,19 +18,19 @@ describe :rb_path_to_class, shared: true do end it "raises an ArgumentError if a constant in the path does not exist" do - lambda { @s.send(@method, "CApiClassSpecs::NotDefined::B") }.should raise_error(ArgumentError) + -> { @s.send(@method, "CApiClassSpecs::NotDefined::B") }.should raise_error(ArgumentError) end it "raises an ArgumentError if the final constant does not exist" do - lambda { @s.send(@method, "CApiClassSpecs::NotDefined") }.should raise_error(ArgumentError) + -> { @s.send(@method, "CApiClassSpecs::NotDefined") }.should raise_error(ArgumentError) end it "raises a TypeError if the constant is not a class or module" do - lambda { @s.send(@method, "CApiClassSpecs::A::C") }.should raise_error(TypeError) + -> { @s.send(@method, "CApiClassSpecs::A::C") }.should raise_error(TypeError) end it "raises an ArgumentError even if a constant in the path exists on toplevel" do - lambda { @s.send(@method, "CApiClassSpecs::Object") }.should raise_error(ArgumentError) + -> { @s.send(@method, "CApiClassSpecs::Object") }.should raise_error(ArgumentError) end end @@ -56,7 +56,7 @@ describe "C-API Class function" do it "includes a module into a class" do c = Class.new o = c.new - lambda { o.included? }.should raise_error(NameError) + -> { o.included? }.should raise_error(NameError) @s.rb_include_module(c, CApiClassSpecs::M) o.included?.should be_true end @@ -70,12 +70,12 @@ describe "C-API Class function" do it "defines an attr_reader when passed true, false" do @s.rb_define_attr(CApiClassSpecs::Attr, :foo, true, false) @a.foo.should == 1 - lambda { @a.foo = 5 }.should raise_error(NameError) + -> { @a.foo = 5 }.should raise_error(NameError) end it "defines an attr_writer when passed false, true" do @s.rb_define_attr(CApiClassSpecs::Attr, :bar, false, true) - lambda { @a.bar }.should raise_error(NameError) + -> { @a.bar }.should raise_error(NameError) @a.bar = 5 @a.instance_variable_get(:@bar).should == 5 end @@ -187,7 +187,7 @@ describe "C-API Class function" do end it "raises a NameError if the class variable is not defined" do - lambda { + -> { @s.rb_cv_get(CApiClassSpecs::CVars, "@@no_cvar") }.should raise_error(NameError, /class variable @@no_cvar/) end @@ -226,19 +226,19 @@ describe "C-API Class function" do end it "raises a TypeError when given a non class object to superclass" do - lambda { + -> { @s.rb_define_class("ClassSpecDefineClass3", Module.new) }.should raise_error(TypeError) end it "raises a TypeError when given a mismatched class to superclass" do - lambda { + -> { @s.rb_define_class("ClassSpecDefineClass", Object) }.should raise_error(TypeError) end it "raises a ArgumentError when given NULL as superclass" do - lambda { + -> { @s.rb_define_class("ClassSpecDefineClass4", nil) }.should raise_error(ArgumentError) end @@ -265,7 +265,7 @@ describe "C-API Class function" do end it "raises a TypeError when given a non class object to superclass" do - lambda { @s.rb_define_class_under(CApiClassSpecs, + -> { @s.rb_define_class_under(CApiClassSpecs, "ClassUnder5", Module.new) }.should raise_error(TypeError) @@ -273,7 +273,7 @@ describe "C-API Class function" do it "raises a TypeError when given a mismatched class to superclass" do CApiClassSpecs::ClassUnder6 = Class.new(CApiClassSpecs::Super) - lambda { @s.rb_define_class_under(CApiClassSpecs, + -> { @s.rb_define_class_under(CApiClassSpecs, "ClassUnder6", Class.new) }.should raise_error(TypeError) @@ -284,7 +284,7 @@ describe "C-API Class function" do end it "raises a TypeError if class is defined and its superclass mismatches the given one" do - lambda { @s.rb_define_class_under(CApiClassSpecs, "Sub", Object) }.should raise_error(TypeError) + -> { @s.rb_define_class_under(CApiClassSpecs, "Sub", Object) }.should raise_error(TypeError) end end @@ -311,7 +311,7 @@ describe "C-API Class function" do end it "raises a TypeError if class is defined and its superclass mismatches the given one" do - lambda { @s.rb_define_class_id_under(CApiClassSpecs, :Sub, Object) }.should raise_error(TypeError) + -> { @s.rb_define_class_id_under(CApiClassSpecs, :Sub, Object) }.should raise_error(TypeError) end end @@ -331,7 +331,7 @@ describe "C-API Class function" do end it "raises a NameError if the class variable is not defined" do - lambda { + -> { @s.rb_cvar_get(CApiClassSpecs::CVars, "@@no_cvar") }.should raise_error(NameError, /class variable @@no_cvar/) end @@ -344,12 +344,12 @@ describe "C-API Class function" do end it "raises a TypeError if passed Class as the superclass" do - lambda { @s.rb_class_new(Class) }.should raise_error(TypeError) + -> { @s.rb_class_new(Class) }.should raise_error(TypeError) end it "raises a TypeError if passed a singleton class as the superclass" do metaclass = Object.new.singleton_class - lambda { @s.rb_class_new(metaclass) }.should raise_error(TypeError) + -> { @s.rb_class_new(metaclass) }.should raise_error(TypeError) end end diff --git a/spec/ruby/optional/capi/data_spec.rb b/spec/ruby/optional/capi/data_spec.rb index dd99581824..c03b863678 100644 --- a/spec/ruby/optional/capi/data_spec.rb +++ b/spec/ruby/optional/capi/data_spec.rb @@ -32,7 +32,7 @@ describe "CApiWrappedStruct" do end it "raises a TypeError if the object does not wrap a struct" do - lambda { @s.get_struct(Object.new) }.should raise_error(TypeError) + -> { @s.get_struct(Object.new) }.should raise_error(TypeError) end end diff --git a/spec/ruby/optional/capi/encoding_spec.rb b/spec/ruby/optional/capi/encoding_spec.rb index 42e7899c9f..003edc9669 100644 --- a/spec/ruby/optional/capi/encoding_spec.rb +++ b/spec/ruby/optional/capi/encoding_spec.rb @@ -21,7 +21,7 @@ describe :rb_enc_set_index, shared: true do # This is used because indexes should be considered implementation # dependent. So a pair is returned: - # [rb_enc_find_index()->name, rb_enc_get(obj)->name] + # [rb_enc_find_index() -> name, rb_enc_get(obj) -> name] result.first.should == result.last end @@ -308,7 +308,7 @@ describe "C-API Encoding function" do end it "raises a RuntimeError if the second argument is a Symbol" do - lambda { @s.rb_enc_copy(:symbol, @obj) }.should raise_error(RuntimeError) + -> { @s.rb_enc_copy(:symbol, @obj) }.should raise_error(RuntimeError) end it "sets the encoding of a Regexp to that of the second argument" do @@ -359,7 +359,7 @@ describe "C-API Encoding function" do end it "raises a RuntimeError if the argument is Symbol" do - lambda { @s.rb_enc_associate(:symbol, "US-ASCII") }.should raise_error(RuntimeError) + -> { @s.rb_enc_associate(:symbol, "US-ASCII") }.should raise_error(RuntimeError) end it "sets the encoding of a Regexp to the encoding" do @@ -386,7 +386,7 @@ describe "C-API Encoding function" do it "sets the encoding of a Symbol to the encoding" do index = @s.rb_enc_find_index("UTF-8") - lambda { @s.rb_enc_associate_index(:symbol, index) }.should raise_error(RuntimeError) + -> { @s.rb_enc_associate_index(:symbol, index) }.should raise_error(RuntimeError) end end @@ -440,13 +440,13 @@ describe "C-API Encoding function" do describe "rb_enc_codepoint_len" do it "raises ArgumentError if an empty string is given" do - lambda do + -> do @s.rb_enc_codepoint_len("") end.should raise_error(ArgumentError) end it "raises ArgumentError if an invalid byte sequence is given" do - lambda do + -> do @s.rb_enc_codepoint_len([0xa0, 0xa1].pack('CC').force_encoding('utf-8')) # Invalid sequence identifier end.should raise_error(ArgumentError) end diff --git a/spec/ruby/optional/capi/exception_spec.rb b/spec/ruby/optional/capi/exception_spec.rb index fb0d4fb54d..62d7d3706e 100644 --- a/spec/ruby/optional/capi/exception_spec.rb +++ b/spec/ruby/optional/capi/exception_spec.rb @@ -28,13 +28,13 @@ describe "C-API Exception function" do describe "rb_exc_raise" do it "raises passed exception" do runtime_error = RuntimeError.new '42' - lambda { @s.rb_exc_raise(runtime_error) }.should raise_error(RuntimeError, '42') + -> { @s.rb_exc_raise(runtime_error) }.should raise_error(RuntimeError, '42') end it "raises an exception with an empty backtrace" do runtime_error = RuntimeError.new '42' runtime_error.set_backtrace [] - lambda { @s.rb_exc_raise(runtime_error) }.should raise_error(RuntimeError, '42') + -> { @s.rb_exc_raise(runtime_error) }.should raise_error(RuntimeError, '42') end end @@ -52,7 +52,7 @@ describe "C-API Exception function" do end it "raises a TypeError if the object is not nil or an Exception instance" do - lambda { @s.rb_set_errinfo("error") }.should raise_error(TypeError) + -> { @s.rb_set_errinfo("error") }.should raise_error(TypeError) end end end diff --git a/spec/ruby/optional/capi/file_spec.rb b/spec/ruby/optional/capi/file_spec.rb index 534a03b484..96d731e4fa 100644 --- a/spec/ruby/optional/capi/file_spec.rb +++ b/spec/ruby/optional/capi/file_spec.rb @@ -5,7 +5,7 @@ load_extension('file') describe :rb_file_open, shared: true do it "raises an ArgumentError if passed an empty mode string" do touch @name - lambda { @s.rb_file_open(@name, "") }.should raise_error(ArgumentError) + -> { @s.rb_file_open(@name, "") }.should raise_error(ArgumentError) end it "opens a file in read-only mode with 'r'" do diff --git a/spec/ruby/optional/capi/fixnum_spec.rb b/spec/ruby/optional/capi/fixnum_spec.rb index dffe3da0bb..aa02a0543b 100644 --- a/spec/ruby/optional/capi/fixnum_spec.rb +++ b/spec/ruby/optional/capi/fixnum_spec.rb @@ -27,7 +27,7 @@ describe "CApiFixnumSpecs" do platform_is wordsize: 64 do # sizeof(long) > sizeof(int) it "raises a TypeError if passed nil" do - lambda { @s.FIX2INT(nil) }.should raise_error(TypeError) + -> { @s.FIX2INT(nil) }.should raise_error(TypeError) end it "converts a Float" do @@ -39,16 +39,16 @@ describe "CApiFixnumSpecs" do end it "raises a RangeError if the value does not fit a native int" do - lambda { @s.FIX2INT(0x7fff_ffff+1) }.should raise_error(RangeError) - lambda { @s.FIX2INT(-(1 << 31) - 1) }.should raise_error(RangeError) + -> { @s.FIX2INT(0x7fff_ffff+1) }.should raise_error(RangeError) + -> { @s.FIX2INT(-(1 << 31) - 1) }.should raise_error(RangeError) end it "raises a RangeError if the value is more than 32bits" do - lambda { @s.FIX2INT(0xffff_ffff+1) }.should raise_error(RangeError) + -> { @s.FIX2INT(0xffff_ffff+1) }.should raise_error(RangeError) end it "raises a RangeError if the value is more than 64bits" do - lambda { @s.FIX2INT(0xffff_ffff_ffff_ffff+1) }.should raise_error(RangeError) + -> { @s.FIX2INT(0xffff_ffff_ffff_ffff+1) }.should raise_error(RangeError) end it "calls #to_int to coerce the value" do @@ -76,7 +76,7 @@ describe "CApiFixnumSpecs" do platform_is wordsize: 64 do # sizeof(long) > sizeof(int) it "raises a TypeError if passed nil" do - lambda { @s.FIX2UINT(nil) }.should raise_error(TypeError) + -> { @s.FIX2UINT(nil) }.should raise_error(TypeError) end it "converts a Float" do @@ -85,16 +85,16 @@ describe "CApiFixnumSpecs" do it "raises a RangeError if the value does not fit a native uint" do # Interestingly, on MRI FIX2UINT(-1) is allowed - lambda { @s.FIX2UINT(0xffff_ffff+1) }.should raise_error(RangeError) - lambda { @s.FIX2UINT(-(1 << 31) - 1) }.should raise_error(RangeError) + -> { @s.FIX2UINT(0xffff_ffff+1) }.should raise_error(RangeError) + -> { @s.FIX2UINT(-(1 << 31) - 1) }.should raise_error(RangeError) end it "raises a RangeError if the value is more than 32bits" do - lambda { @s.FIX2UINT(0xffff_ffff+1) }.should raise_error(RangeError) + -> { @s.FIX2UINT(0xffff_ffff+1) }.should raise_error(RangeError) end it "raises a RangeError if the value is more than 64bits" do - lambda { @s.FIX2UINT(0xffff_ffff_ffff_ffff+1) }.should raise_error(RangeError) + -> { @s.FIX2UINT(0xffff_ffff_ffff_ffff+1) }.should raise_error(RangeError) end end end diff --git a/spec/ruby/optional/capi/globals_spec.rb b/spec/ruby/optional/capi/globals_spec.rb index 0bded557ba..84694b1375 100644 --- a/spec/ruby/optional/capi/globals_spec.rb +++ b/spec/ruby/optional/capi/globals_spec.rb @@ -44,7 +44,7 @@ describe "CApiGlobalSpecs" do it "rb_define_readonly_variable should define a new readonly global variable" do @f.rb_define_readonly_variable("ro_gvar", 15) $ro_gvar.should == 15 - lambda { $ro_gvar = 10 }.should raise_error(NameError) + -> { $ro_gvar = 10 }.should raise_error(NameError) end it "rb_define_hooked_variable should define a C hooked global variable" do diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb index 92dc62d55b..2923faf7de 100644 --- a/spec/ruby/optional/capi/hash_spec.rb +++ b/spec/ruby/optional/capi/hash_spec.rb @@ -36,7 +36,7 @@ describe "C-API Hash function" do obj = mock("rb_hash no to_int") obj.should_receive(:hash).and_return(nil) - lambda { @s.rb_hash(obj) }.should raise_error(TypeError) + -> { @s.rb_hash(obj) }.should raise_error(TypeError) end end @@ -131,15 +131,15 @@ describe "C-API Hash function" do it "raises a KeyError if the key is not found and default is set" do @hsh.default = :d - lambda { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError) + -> { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError) end it "raises a KeyError if the key is not found and no default is set" do - lambda { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError) + -> { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError) end context "when key is not found" do - it_behaves_like :key_error, -> (obj, key) { + it_behaves_like :key_error, -> obj, key { @s.rb_hash_fetch(obj, key) }, { a: 1 } end @@ -245,13 +245,13 @@ describe "C-API Hash function" do end it "raises a TypeError if the argument does not respond to #to_hash" do - lambda { @s.rb_Hash(42) }.should raise_error(TypeError) + -> { @s.rb_Hash(42) }.should raise_error(TypeError) end it "raises a TypeError if #to_hash does not return a hash" do h = BasicObject.new def h.to_hash; 42; end - lambda { @s.rb_Hash(h) }.should raise_error(TypeError) + -> { @s.rb_Hash(h) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/optional/capi/io_spec.rb b/spec/ruby/optional/capi/io_spec.rb index 622c770eef..7947a48eac 100644 --- a/spec/ruby/optional/capi/io_spec.rb +++ b/spec/ruby/optional/capi/io_spec.rb @@ -142,12 +142,12 @@ describe "C-API IO function" do describe "rb_io_check_closed" do it "does not raise an exception if the IO is not closed" do # The MRI function is void, so we use should_not raise_error - lambda { @o.rb_io_check_closed(@io) }.should_not raise_error + -> { @o.rb_io_check_closed(@io) }.should_not raise_error end it "raises an error if the IO is closed" do @io.close - lambda { @o.rb_io_check_closed(@io) }.should raise_error(IOError) + -> { @o.rb_io_check_closed(@io) }.should raise_error(IOError) end end @@ -155,13 +155,13 @@ describe "C-API IO function" do # object is frozen, *not* if it's tainted. describe "rb_io_taint_check" do it "does not raise an exception if the IO is not frozen" do - lambda { @o.rb_io_taint_check(@io) }.should_not raise_error + -> { @o.rb_io_taint_check(@io) }.should_not raise_error end it "raises an exception if the IO is frozen" do @io.freeze - lambda { @o.rb_io_taint_check(@io) }.should raise_error(RuntimeError) + -> { @o.rb_io_taint_check(@io) }.should raise_error(RuntimeError) end end @@ -206,15 +206,15 @@ describe "C-API IO function" do describe "rb_io_check_readable" do it "does not raise an exception if the IO is opened for reading" do # The MRI function is void, so we use should_not raise_error - lambda { @o.rb_io_check_readable(@r_io) }.should_not raise_error + -> { @o.rb_io_check_readable(@r_io) }.should_not raise_error end it "does not raise an exception if the IO is opened for read and write" do - lambda { @o.rb_io_check_readable(@rw_io) }.should_not raise_error + -> { @o.rb_io_check_readable(@rw_io) }.should_not raise_error end it "raises an IOError if the IO is not opened for reading" do - lambda { @o.rb_io_check_readable(@w_io) }.should raise_error(IOError) + -> { @o.rb_io_check_readable(@w_io) }.should raise_error(IOError) end end @@ -222,15 +222,15 @@ describe "C-API IO function" do describe "rb_io_check_writable" do it "does not raise an exeption if the IO is opened for writing" do # The MRI function is void, so we use should_not raise_error - lambda { @o.rb_io_check_writable(@w_io) }.should_not raise_error + -> { @o.rb_io_check_writable(@w_io) }.should_not raise_error end it "does not raise an exception if the IO is opened for read and write" do - lambda { @o.rb_io_check_writable(@rw_io) }.should_not raise_error + -> { @o.rb_io_check_writable(@rw_io) }.should_not raise_error end it "raises an IOError if the IO is not opened for reading" do - lambda { @o.rb_io_check_writable(@r_io) }.should raise_error(IOError) + -> { @o.rb_io_check_writable(@r_io) }.should raise_error(IOError) end end @@ -242,7 +242,7 @@ describe "C-API IO function" do it "raises an IOError if the IO is closed" do @w_io.close - lambda { @o.rb_io_wait_writable(@w_io) }.should raise_error(IOError) + -> { @o.rb_io_wait_writable(@w_io) }.should raise_error(IOError) end end @@ -261,7 +261,7 @@ describe "C-API IO function" do it "raises and IOError if passed a closed stream" do @r_io.close - lambda { + -> { @o.rb_io_wait_readable(@r_io, false) }.should raise_error(IOError) end diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index 3fb2c8ed2d..d123eb13ea 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -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 diff --git a/spec/ruby/optional/capi/module_spec.rb b/spec/ruby/optional/capi/module_spec.rb index b94e96e846..34e6db82d8 100644 --- a/spec/ruby/optional/capi/module_spec.rb +++ b/spec/ruby/optional/capi/module_spec.rb @@ -54,7 +54,7 @@ describe "CApiModule" do it "raises a TypeError if the constant is not a module" do ::CApiModuleSpecsGlobalConst = 7 - lambda { @m.rb_define_module("CApiModuleSpecsGlobalConst") }.should raise_error(TypeError) + -> { @m.rb_define_module("CApiModuleSpecsGlobalConst") }.should raise_error(TypeError) Object.send :remove_const, :CApiModuleSpecsGlobalConst end @@ -303,7 +303,7 @@ describe "CApiModule" do a = cls.new @m.rb_define_singleton_method a, "module_specs_singleton_method" a.module_specs_singleton_method.should == :test_method - lambda { cls.new.module_specs_singleton_method }.should raise_error(NoMethodError) + -> { cls.new.module_specs_singleton_method }.should raise_error(NoMethodError) end end @@ -323,7 +323,7 @@ describe "CApiModule" do end it "does not raise exceptions when passed a missing name" do - lambda { @m.rb_undef_method @class, "not_exist" }.should_not raise_error + -> { @m.rb_undef_method @class, "not_exist" }.should_not raise_error end describe "when given a frozen Class" do @@ -332,11 +332,11 @@ describe "CApiModule" do end it "raises a #{frozen_error_class} when passed a name" do - lambda { @m.rb_undef_method @frozen, "ruby_test_method" }.should raise_error(frozen_error_class) + -> { @m.rb_undef_method @frozen, "ruby_test_method" }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} when passed a missing name" do - lambda { @m.rb_undef_method @frozen, "not_exist" }.should raise_error(frozen_error_class) + -> { @m.rb_undef_method @frozen, "not_exist" }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/optional/capi/mutex_spec.rb b/spec/ruby/optional/capi/mutex_spec.rb index 1b76c5c250..34659974f5 100644 --- a/spec/ruby/optional/capi/mutex_spec.rb +++ b/spec/ruby/optional/capi/mutex_spec.rb @@ -46,14 +46,14 @@ describe "C-API Mutex functions" do it "throws an exception when already locked in the same thread" do @m.lock - lambda { @s.rb_mutex_lock(@m) }.should raise_error(ThreadError) + -> { @s.rb_mutex_lock(@m) }.should raise_error(ThreadError) @m.locked?.should be_true end end describe "rb_mutex_unlock" do it "raises an exception when not locked" do - lambda { @s.rb_mutex_unlock(@m) }.should raise_error(ThreadError) + -> { @s.rb_mutex_unlock(@m) }.should raise_error(ThreadError) @m.locked?.should be_false end @@ -66,7 +66,7 @@ describe "C-API Mutex functions" do describe "rb_mutex_sleep" do it "throws an exception when the mutex is not locked" do - lambda { @s.rb_mutex_sleep(@m, 0.1) }.should raise_error(ThreadError) + -> { @s.rb_mutex_sleep(@m, 0.1) }.should raise_error(ThreadError) @m.locked?.should be_false end @@ -82,7 +82,7 @@ describe "C-API Mutex functions" do describe "rb_mutex_synchronize" do it "calls the function while the mutex is locked" do - callback = lambda { @m.locked?.should be_true } + callback = -> { @m.locked?.should be_true } @s.rb_mutex_synchronize(@m, callback) end end diff --git a/spec/ruby/optional/capi/numeric_spec.rb b/spec/ruby/optional/capi/numeric_spec.rb index 62921f2467..d76f353850 100644 --- a/spec/ruby/optional/capi/numeric_spec.rb +++ b/spec/ruby/optional/capi/numeric_spec.rb @@ -9,7 +9,7 @@ describe "CApiNumericSpecs" do describe "NUM2INT" do it "raises a TypeError if passed nil" do - lambda { @s.NUM2INT(nil) }.should raise_error(TypeError) + -> { @s.NUM2INT(nil) }.should raise_error(TypeError) end it "converts a Float" do @@ -33,7 +33,7 @@ describe "CApiNumericSpecs" do end it "raises a RangeError if the value is more than 32bits" do - lambda { @s.NUM2INT(0xffff_ffff+1) }.should raise_error(RangeError) + -> { @s.NUM2INT(0xffff_ffff+1) }.should raise_error(RangeError) end it "calls #to_int to coerce the value" do @@ -45,7 +45,7 @@ describe "CApiNumericSpecs" do describe "NUM2UINT" do it "raises a TypeError if passed nil" do - lambda { @s.NUM2UINT(nil) }.should raise_error(TypeError) + -> { @s.NUM2UINT(nil) }.should raise_error(TypeError) end it "converts a Float" do @@ -69,15 +69,15 @@ describe "CApiNumericSpecs" do end it "raises a RangeError if the value is more than 32bits" do - lambda { @s.NUM2UINT(0xffff_ffff+1) }.should raise_error(RangeError) + -> { @s.NUM2UINT(0xffff_ffff+1) }.should raise_error(RangeError) end it "raises a RangeError if the value is less than 32bits negative" do - lambda { @s.NUM2UINT(-0x8000_0000-1) }.should raise_error(RangeError) + -> { @s.NUM2UINT(-0x8000_0000-1) }.should raise_error(RangeError) end it "raises a RangeError if the value is more than 64bits" do - lambda do + -> do @s.NUM2UINT(0xffff_ffff_ffff_ffff+1) end.should raise_error(RangeError) end @@ -91,7 +91,7 @@ describe "CApiNumericSpecs" do describe "NUM2LONG" do it "raises a TypeError if passed nil" do - lambda { @s.NUM2LONG(nil) }.should raise_error(TypeError) + -> { @s.NUM2LONG(nil) }.should raise_error(TypeError) end it "converts a Float" do @@ -116,7 +116,7 @@ describe "CApiNumericSpecs" do end it "raises a RangeError if the value is more than 32bits" do - lambda { @s.NUM2LONG(0xffff_ffff+1) }.should raise_error(RangeError) + -> { @s.NUM2LONG(0xffff_ffff+1) }.should raise_error(RangeError) end end @@ -130,7 +130,7 @@ describe "CApiNumericSpecs" do end it "raises a RangeError if the value is more than 64bits" do - lambda do + -> do @s.NUM2LONG(0xffff_ffff_ffff_ffff+1) end.should raise_error(RangeError) end @@ -145,7 +145,7 @@ describe "CApiNumericSpecs" do describe "INT2NUM" do it "raises a TypeError if passed nil" do - lambda { @s.INT2NUM(nil) }.should raise_error(TypeError) + -> { @s.INT2NUM(nil) }.should raise_error(TypeError) end it "converts a Float" do @@ -153,7 +153,7 @@ describe "CApiNumericSpecs" do end it "raises a RangeError when passed a Bignum" do - lambda { @s.INT2NUM(bignum_value) }.should raise_error(RangeError) + -> { @s.INT2NUM(bignum_value) }.should raise_error(RangeError) end it "converts a Fixnum" do @@ -167,7 +167,7 @@ describe "CApiNumericSpecs" do describe "NUM2ULONG" do it "raises a TypeError if passed nil" do - lambda { @s.NUM2ULONG(nil) }.should raise_error(TypeError) + -> { @s.NUM2ULONG(nil) }.should raise_error(TypeError) end it "converts a Float" do @@ -199,7 +199,7 @@ describe "CApiNumericSpecs" do end it "raises a RangeError if the value is more than 32bits" do - lambda { @s.NUM2ULONG(0xffff_ffff+1) }.should raise_error(RangeError) + -> { @s.NUM2ULONG(0xffff_ffff+1) }.should raise_error(RangeError) end end @@ -220,7 +220,7 @@ describe "CApiNumericSpecs" do end it "raises a RangeError if the value is more than 64bits" do - lambda do + -> do @s.NUM2ULONG(0xffff_ffff_ffff_ffff+1) end.should raise_error(RangeError) end @@ -287,11 +287,11 @@ describe "CApiNumericSpecs" do describe "NUM2DBL" do it "raises a TypeError if passed nil" do - lambda { @s.NUM2DBL(nil) }.should raise_error(TypeError) + -> { @s.NUM2DBL(nil) }.should raise_error(TypeError) end it "raises a TypeError if passed a String" do - lambda { @s.NUM2DBL("1.2") }.should raise_error(TypeError) + -> { @s.NUM2DBL("1.2") }.should raise_error(TypeError) end it "converts a Float" do @@ -327,13 +327,13 @@ describe "CApiNumericSpecs" do end it "raises a TypeError when passed an empty String" do - lambda { @s.NUM2CHR("") }.should raise_error(TypeError) + -> { @s.NUM2CHR("") }.should raise_error(TypeError) end end describe "rb_num_zerodiv" do it "raises a RuntimeError" do - lambda { @s.rb_num_zerodiv() }.should raise_error(ZeroDivisionError, 'divided by 0') + -> { @s.rb_num_zerodiv() }.should raise_error(ZeroDivisionError, 'divided by 0') end end @@ -363,7 +363,7 @@ describe "CApiNumericSpecs" do end it "raises an ArgumentError when passed nil" do - lambda { + -> { @s.rb_cmpint(nil, 4) }.should raise_error(ArgumentError) end @@ -389,7 +389,7 @@ describe "CApiNumericSpecs" do obj = mock("rb_num_coerce_bin") obj.should_receive(:coerce).with(2).and_return(nil) - lambda { @s.rb_num_coerce_bin(2, obj, :+) }.should raise_error(TypeError) + -> { @s.rb_num_coerce_bin(2, obj, :+) }.should raise_error(TypeError) end end @@ -457,14 +457,14 @@ describe "CApiNumericSpecs" do obj.should_receive(:coerce).with(2).and_return([obj, 2]) obj.should_receive(:<).with(2).and_return(nil) - lambda { @s.rb_num_coerce_relop(2, obj, :<) }.should raise_error(ArgumentError) + -> { @s.rb_num_coerce_relop(2, obj, :<) }.should raise_error(ArgumentError) end it "raises an ArgumentError if #coerce does not return an Array" do obj = mock("rb_num_coerce_relop") obj.should_receive(:coerce).with(2).and_return(nil) - lambda { @s.rb_num_coerce_relop(2, obj, :<) }.should raise_error(ArgumentError) + -> { @s.rb_num_coerce_relop(2, obj, :<) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb index 34aae636c7..43b74b9151 100644 --- a/spec/ruby/optional/capi/object_spec.rb +++ b/spec/ruby/optional/capi/object_spec.rb @@ -230,7 +230,7 @@ describe "CApiObject" do obj = mock("rb_check_convert_type") obj.should_receive(:to_array).and_return("string") - lambda do + -> do @o.rb_check_convert_type(obj, "Array", "to_array") end.should raise_error(TypeError) end @@ -255,7 +255,7 @@ describe "CApiObject" do obj = mock("rb_convert_type") obj.should_receive(:to_array).and_return(nil) - lambda do + -> do @o.rb_convert_type(obj, "Array", "to_array") end.should raise_error(TypeError) end @@ -264,7 +264,7 @@ describe "CApiObject" do obj = mock("rb_convert_type") obj.should_receive(:to_array).and_return("string") - lambda do + -> do @o.rb_convert_type(obj, "Array", "to_array") end.should raise_error(TypeError) end @@ -308,13 +308,13 @@ describe "CApiObject" do it "sends #to_ary to the argument and raises TypeError if it's not a kind of Array" do obj = mock("to_ary") obj.should_receive(:to_ary).and_return(Object.new) - lambda { @o.rb_check_array_type obj }.should raise_error(TypeError) + -> { @o.rb_check_array_type obj }.should raise_error(TypeError) end it "does not rescue exceptions raised by #to_ary" do obj = mock("to_ary") obj.should_receive(:to_ary).and_raise(frozen_error_class) - lambda { @o.rb_check_array_type obj }.should raise_error(frozen_error_class) + -> { @o.rb_check_array_type obj }.should raise_error(frozen_error_class) end end @@ -356,13 +356,13 @@ describe "CApiObject" do it "sends #to_str to the argument and raises TypeError if it's not a kind of String" do obj = mock("to_str") obj.should_receive(:to_str).and_return(Object.new) - lambda { @o.rb_check_string_type obj }.should raise_error(TypeError) + -> { @o.rb_check_string_type obj }.should raise_error(TypeError) end it "does not rescue exceptions raised by #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_raise(RuntimeError) - lambda { @o.rb_check_string_type obj }.should raise_error(RuntimeError) + -> { @o.rb_check_string_type obj }.should raise_error(RuntimeError) end end @@ -639,7 +639,7 @@ describe "CApiObject" do describe "rb_obj_instance_eval" do it "evaluates the block in the object context, that includes private methods" do obj = ObjectTest - lambda do + -> do @o.rb_obj_instance_eval(obj) { include Kernel } end.should_not raise_error(NoMethodError) end @@ -667,18 +667,18 @@ describe "CApiObject" do end it "raises a #{frozen_error_class} if the object passed is frozen" do - lambda { @o.rb_obj_taint("".freeze) }.should raise_error(frozen_error_class) + -> { @o.rb_obj_taint("".freeze) }.should raise_error(frozen_error_class) end end describe "rb_check_frozen" do it "raises a #{frozen_error_class} if the obj is frozen" do - lambda { @o.rb_check_frozen("".freeze) }.should raise_error(frozen_error_class) + -> { @o.rb_check_frozen("".freeze) }.should raise_error(frozen_error_class) end it "does nothing when object isn't frozen" do obj = "" - lambda { @o.rb_check_frozen(obj) }.should_not raise_error(TypeError) + -> { @o.rb_check_frozen(obj) }.should_not raise_error(TypeError) end end @@ -718,23 +718,23 @@ describe "CApiObject" do it "raises a TypeError if #to_int does not return an Integer" do x = mock("to_int") x.should_receive(:to_int).and_return("5") - lambda { @o.rb_to_int(x) }.should raise_error(TypeError) + -> { @o.rb_to_int(x) }.should raise_error(TypeError) end it "raises a TypeError if called with nil" do - lambda { @o.rb_to_int(nil) }.should raise_error(TypeError) + -> { @o.rb_to_int(nil) }.should raise_error(TypeError) end it "raises a TypeError if called with true" do - lambda { @o.rb_to_int(true) }.should raise_error(TypeError) + -> { @o.rb_to_int(true) }.should raise_error(TypeError) end it "raises a TypeError if called with false" do - lambda { @o.rb_to_int(false) }.should raise_error(TypeError) + -> { @o.rb_to_int(false) }.should raise_error(TypeError) end it "raises a TypeError if called with a String" do - lambda { @o.rb_to_int("1") }.should raise_error(TypeError) + -> { @o.rb_to_int("1") }.should raise_error(TypeError) end end @@ -770,7 +770,7 @@ describe "CApiObject" do end it "raises a TypeError if arg is no class or module" do - lambda{ + ->{ @o.rb_class_inherited_p(1, 2) }.should raise_error(TypeError) end diff --git a/spec/ruby/optional/capi/proc_spec.rb b/spec/ruby/optional/capi/proc_spec.rb index bffb32484c..9f9a37cc98 100644 --- a/spec/ruby/optional/capi/proc_spec.rb +++ b/spec/ruby/optional/capi/proc_spec.rb @@ -86,13 +86,13 @@ describe "C-API when calling Proc.new from a C function" do # Ruby -> C -> Ruby -> Proc.new it "raises an ArgumentError when the C function calls a Ruby method that calls Proc.new" do def @p.Proc_new() Proc.new end - lambda { @p.rb_Proc_new(2) { :called } }.should raise_error(ArgumentError) + -> { @p.rb_Proc_new(2) { :called } }.should raise_error(ArgumentError) end # Ruby -> C -> Ruby -> C -> rb_funcall(Proc.new) it "raises an ArgumentError when the C function calls a Ruby method and that method calls a C function that calls Proc.new" do def @p.redispatch() rb_Proc_new(0) end - lambda { @p.rb_Proc_new(3) { :called } }.should raise_error(ArgumentError) + -> { @p.rb_Proc_new(3) { :called } }.should raise_error(ArgumentError) end ruby_version_is ""..."2.7" do diff --git a/spec/ruby/optional/capi/range_spec.rb b/spec/ruby/optional/capi/range_spec.rb index 46df4eec99..7a52dc7ff8 100644 --- a/spec/ruby/optional/capi/range_spec.rb +++ b/spec/ruby/optional/capi/range_spec.rb @@ -31,8 +31,8 @@ describe "C-API Range function" do end it "raises an ArgumentError when the given start and end can't be compared by using #<=>" do - lambda { @s.rb_range_new(1, mock('x')) }.should raise_error(ArgumentError) - lambda { @s.rb_range_new(mock('x'), mock('y')) }.should raise_error(ArgumentError) + -> { @s.rb_range_new(1, mock('x')) }.should raise_error(ArgumentError) + -> { @s.rb_range_new(mock('x'), mock('y')) }.should raise_error(ArgumentError) end end @@ -83,7 +83,7 @@ describe "C-API Range function" do it "raises a RangeError when not in range and err is 1" do r = -5..-1 - lambda { @s.rb_range_beg_len(r, 0, 0, 1, 1) }.should raise_error(RangeError) + -> { @s.rb_range_beg_len(r, 0, 0, 1, 1) }.should raise_error(RangeError) end it "returns nil when not in range and err is 0" do diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 432008e825..469a190abd 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -327,7 +327,7 @@ describe "C-API String function" do end it "raises a TypeError trying to append non-String-like object" do - lambda { @s.rb_str_append("Hello", 32323)}.should raise_error(TypeError) + -> { @s.rb_str_append("Hello", 32323)}.should raise_error(TypeError) end it "changes Encoding if a string is appended to an empty string" do @@ -343,7 +343,7 @@ describe "C-API String function" do end describe "rb_str_times" do - it_behaves_like :string_times, :rb_str_times, ->(str, times) { @s.rb_str_times(str, times) } + it_behaves_like :string_times, :rb_str_times, -> str, times { @s.rb_str_times(str, times) } end describe "rb_str_buf_cat" do @@ -414,7 +414,7 @@ describe "C-API String function" do end it "converts a C string to a Fixnum strictly if base is 0" do - lambda { @s.rb_cstr2inum("1234a", 0) }.should raise_error(ArgumentError) + -> { @s.rb_cstr2inum("1234a", 0) }.should raise_error(ArgumentError) end end @@ -432,7 +432,7 @@ describe "C-API String function" do end it "converts a C string to a Fixnum strictly" do - lambda { @s.rb_cstr_to_inum("1234a", 10, true) }.should raise_error(ArgumentError) + -> { @s.rb_cstr_to_inum("1234a", 10, true) }.should raise_error(ArgumentError) end end @@ -458,8 +458,8 @@ describe "C-API String function" do end it "raises a TypeError if coercion fails" do - lambda { @s.rb_str_to_str(0) }.should raise_error(TypeError) - lambda { @s.rb_str_to_str(CApiStringSpecs::InvalidTostrTest.new) }.should raise_error(TypeError) + -> { @s.rb_str_to_str(0) }.should raise_error(TypeError) + -> { @s.rb_str_to_str(CApiStringSpecs::InvalidTostrTest.new) }.should raise_error(TypeError) end end @@ -549,7 +549,7 @@ describe "C-API String function" do it "does not call #to_s on non-String objects" do str = mock("fake") str.should_not_receive(:to_s) - lambda { @s.send(@method, str) }.should raise_error(TypeError) + -> { @s.send(@method, str) }.should raise_error(TypeError) end end @@ -562,7 +562,7 @@ describe "C-API String function" do begin Thread.new { $SAFE = 1 - lambda { + -> { @s.SafeStringValue("str".taint) }.should raise_error(SecurityError) }.join @@ -951,7 +951,7 @@ end end it "raises a TypeError if #to_str does not return a string" do - lambda { @s.rb_String(CApiStringSpecs::InvalidTostrTest.new) }.should raise_error(TypeError) + -> { @s.rb_String(CApiStringSpecs::InvalidTostrTest.new) }.should raise_error(TypeError) end it "tries to convert the passed argument to a string by calling #to_s" do @@ -969,11 +969,11 @@ end end it "raises an error if a string contains a null" do - lambda { @s.rb_string_value_cstr("Hello\0 with a null.") }.should raise_error(ArgumentError) + -> { @s.rb_string_value_cstr("Hello\0 with a null.") }.should raise_error(ArgumentError) end it "raises an error if a UTF-16 string contains a null" do - lambda { @s.rb_string_value_cstr("Hello\0 with a null.".encode('UTF-16BE')) }.should raise_error(ArgumentError) + -> { @s.rb_string_value_cstr("Hello\0 with a null.".encode('UTF-16BE')) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/optional/capi/struct_spec.rb b/spec/ruby/optional/capi/struct_spec.rb index 3b0972926c..6254b098a9 100644 --- a/spec/ruby/optional/capi/struct_spec.rb +++ b/spec/ruby/optional/capi/struct_spec.rb @@ -106,11 +106,11 @@ describe "C-API Struct function" do describe "rb_struct_define" do it "raises an ArgumentError if arguments contain duplicate member name" do - lambda { @s.rb_struct_define(nil, "a", "b", "a") }.should raise_error(ArgumentError) + -> { @s.rb_struct_define(nil, "a", "b", "a") }.should raise_error(ArgumentError) end it "raises a NameError if an invalid constant name is given" do - lambda { @s.rb_struct_define("foo", "a", "b", "c") }.should raise_error(NameError) + -> { @s.rb_struct_define("foo", "a", "b", "c") }.should raise_error(NameError) end end @@ -131,12 +131,12 @@ describe "C-API Struct function" do end it "raises a NameError if the struct member does not exist" do - lambda { @s.rb_struct_aref(@struct, :d) }.should raise_error(NameError) + -> { @s.rb_struct_aref(@struct, :d) }.should raise_error(NameError) end it "raises an IndexError if the given index is out of range" do - lambda { @s.rb_struct_aref(@struct, -4) }.should raise_error(IndexError) - lambda { @s.rb_struct_aref(@struct, 3) }.should raise_error(IndexError) + -> { @s.rb_struct_aref(@struct, -4) }.should raise_error(IndexError) + -> { @s.rb_struct_aref(@struct, 3) }.should raise_error(IndexError) end end @@ -147,7 +147,7 @@ describe "C-API Struct function" do end it "raises a NameError if the struct member does not exist" do - lambda { @s.rb_struct_getmember(@struct, :d) }.should raise_error(NameError) + -> { @s.rb_struct_getmember(@struct, :d) }.should raise_error(NameError) end end @@ -180,17 +180,17 @@ describe "C-API Struct function" do end it "raises a NameError if the struct member does not exist" do - lambda { @s.rb_struct_aset(@struct, :d, 1) }.should raise_error(NameError) + -> { @s.rb_struct_aset(@struct, :d, 1) }.should raise_error(NameError) end it "raises an IndexError if the given index is out of range" do - lambda { @s.rb_struct_aset(@struct, -4, 1) }.should raise_error(IndexError) - lambda { @s.rb_struct_aset(@struct, 3, 1) }.should raise_error(IndexError) + -> { @s.rb_struct_aset(@struct, -4, 1) }.should raise_error(IndexError) + -> { @s.rb_struct_aset(@struct, 3, 1) }.should raise_error(IndexError) end it "raises a #{frozen_error_class} if the struct is frozen" do @struct.freeze - lambda { @s.rb_struct_aset(@struct, :a, 1) }.should raise_error(frozen_error_class) + -> { @s.rb_struct_aset(@struct, :a, 1) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/optional/capi/thread_spec.rb b/spec/ruby/optional/capi/thread_spec.rb index a46290203a..8ff5b48536 100644 --- a/spec/ruby/optional/capi/thread_spec.rb +++ b/spec/ruby/optional/capi/thread_spec.rb @@ -70,7 +70,7 @@ describe "C-API Thread function" do describe "rb_thread_create" do it "creates a new thread" do obj = Object.new - proc = lambda { |x| ScratchPad.record x } + proc = -> x { ScratchPad.record x } thr = @t.rb_thread_create(proc, obj) thr.should be_kind_of(Thread) thr.join @@ -78,20 +78,20 @@ describe "C-API Thread function" do end it "handles throwing an exception in the thread" do - prc = lambda { |x| + prc = -> x { Thread.current.report_on_exception = false raise "my error" } thr = @t.rb_thread_create(prc, nil) thr.should be_kind_of(Thread) - lambda { + -> { thr.join }.should raise_error(RuntimeError, "my error") end it "sets the thread's group" do - thr = @t.rb_thread_create(lambda { |x| }, nil) + thr = @t.rb_thread_create(-> x { }, nil) begin thread_group = thr.group thread_group.should be_an_instance_of(ThreadGroup) @@ -117,10 +117,7 @@ describe "C-API Thread function" do # Wake it up, causing the unblock function to be run. thr.wakeup - # Make sure it stopped - thr.join(1).should_not be_nil - - # And we got a proper value + # Make sure it stopped and we got a proper value thr.value.should be_true end @@ -139,10 +136,7 @@ describe "C-API Thread function" do # Wake it up, causing the unblock function to be run. thr.wakeup - # Make sure it stopped - thr.join(1).should_not be_nil - - # And we got a proper value + # Make sure it stopped and we got a proper value thr.value.should be_true end end diff --git a/spec/ruby/optional/capi/time_spec.rb b/spec/ruby/optional/capi/time_spec.rb index 427507a3bb..2c824bb566 100644 --- a/spec/ruby/optional/capi/time_spec.rb +++ b/spec/ruby/optional/capi/time_spec.rb @@ -96,9 +96,9 @@ describe "CApiTimeSpecs" do end it "throws an argument error for a negative value" do - lambda { @s.rb_time_interval(-1232141421) }.should raise_error(ArgumentError) - lambda { @s.rb_time_interval(Rational(-3, 2)) }.should raise_error(ArgumentError) - lambda { @s.rb_time_interval(-1.5) }.should raise_error(ArgumentError) + -> { @s.rb_time_interval(-1232141421) }.should raise_error(ArgumentError) + -> { @s.rb_time_interval(Rational(-3, 2)) }.should raise_error(ArgumentError) + -> { @s.rb_time_interval(-1.5) }.should raise_error(ArgumentError) end end @@ -129,13 +129,13 @@ describe "CApiTimeSpecs" do end it "throws an argument error for a negative value" do - lambda { @s.rb_time_interval(-1232141421) }.should raise_error(ArgumentError) - lambda { @s.rb_time_interval(Rational(-3, 2)) }.should raise_error(ArgumentError) - lambda { @s.rb_time_interval(-1.5) }.should raise_error(ArgumentError) + -> { @s.rb_time_interval(-1232141421) }.should raise_error(ArgumentError) + -> { @s.rb_time_interval(Rational(-3, 2)) }.should raise_error(ArgumentError) + -> { @s.rb_time_interval(-1.5) }.should raise_error(ArgumentError) end it "throws an argument error when given a Time instance" do - lambda { @s.rb_time_interval(Time.now) }.should raise_error(TypeError) + -> { @s.rb_time_interval(Time.now) }.should raise_error(TypeError) end end @@ -284,8 +284,8 @@ describe "CApiTimeSpecs" do end it "raises an ArgumentError if offset passed is not within range of -86400 and 86400 (exclusive)" do - lambda { @s.rb_time_timespec_new(1447087832, 476451125, 86400) }.should raise_error(ArgumentError) - lambda { @s.rb_time_timespec_new(1447087832, 476451125, -86400) }.should raise_error(ArgumentError) + -> { @s.rb_time_timespec_new(1447087832, 476451125, 86400) }.should raise_error(ArgumentError) + -> { @s.rb_time_timespec_new(1447087832, 476451125, -86400) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/optional/capi/typed_data_spec.rb b/spec/ruby/optional/capi/typed_data_spec.rb index 8d2910457c..da56a050fd 100644 --- a/spec/ruby/optional/capi/typed_data_spec.rb +++ b/spec/ruby/optional/capi/typed_data_spec.rb @@ -30,7 +30,7 @@ describe "CApiWrappedTypedStruct" do it "throws an exception for a wrong type" do a = @s.typed_wrap_struct(1024) - lambda { @s.typed_get_struct_other(a) }.should raise_error(TypeError) + -> { @s.typed_get_struct_other(a) }.should raise_error(TypeError) end it "unwraps data for a parent type" do diff --git a/spec/ruby/optional/capi/util_spec.rb b/spec/ruby/optional/capi/util_spec.rb index 5f8f9c6e3b..cd6c1105e2 100644 --- a/spec/ruby/optional/capi/util_spec.rb +++ b/spec/ruby/optional/capi/util_spec.rb @@ -9,7 +9,7 @@ describe "C-API Util function" do describe "rb_scan_args" do before :each do - @prc = lambda { 1 } + @prc = -> { 1 } @acc = [] ScratchPad.record @acc end @@ -20,11 +20,11 @@ describe "C-API Util function" do end it "raises an ArgumentError if there are insufficient arguments" do - lambda { @o.rb_scan_args([1, 2], "3", 0, @acc) }.should raise_error(ArgumentError) + -> { @o.rb_scan_args([1, 2], "3", 0, @acc) }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are too many arguments" do - lambda { @o.rb_scan_args([1, 2, 3, 4], "3", 0, @acc) }.should raise_error(ArgumentError) + -> { @o.rb_scan_args([1, 2, 3, 4], "3", 0, @acc) }.should raise_error(ArgumentError) end it "assigns the required and optional arguments scanned" do @@ -133,7 +133,7 @@ describe "C-API Util function" do # r43934 it "rejects non-keyword arguments" do h = {1 => 2, 3 => 4} - lambda { + -> { @o.rb_scan_args([h], "0:", 1, @acc) }.should raise_error(ArgumentError) ScratchPad.recorded.should == [] @@ -141,7 +141,7 @@ describe "C-API Util function" do it "rejects required and non-keyword arguments" do h = {1 => 2, 3 => 4} - lambda { + -> { @o.rb_scan_args([1, h], "1:", 2, @acc) }.should raise_error(ArgumentError) ScratchPad.recorded.should == [] @@ -175,7 +175,7 @@ describe "C-API Util function" do it "raises an error if a required argument is not in the hash" do h = { :a => 7, :c => 12, :b => 5 } - lambda { @o.rb_get_kwargs(h, [:b, :d], 2, 0) }.should raise_error(ArgumentError, /missing keyword: d/) + -> { @o.rb_get_kwargs(h, [:b, :d], 2, 0) }.should raise_error(ArgumentError, /missing keyword: d/) h.should == {:a => 7, :c => 12} end @@ -187,7 +187,7 @@ describe "C-API Util function" do it "raises an error if there are additional arguments and optional is positive" do h = { :a => 7, :c => 12, :b => 5 } - lambda { @o.rb_get_kwargs(h, [:b, :a], 2, 0) }.should raise_error(ArgumentError, /unknown keyword: c/) + -> { @o.rb_get_kwargs(h, [:b, :a], 2, 0) }.should raise_error(ArgumentError, /unknown keyword: c/) h.should == {:c => 12} end @@ -201,7 +201,7 @@ describe "C-API Util function" do platform_is wordsize: 64 do describe "rb_long2int" do it "raises a RangeError if the value is outside the range of a C int" do - lambda { @o.rb_long2int(0xffff_ffff_ffff) }.should raise_error(RangeError) + -> { @o.rb_long2int(0xffff_ffff_ffff) }.should raise_error(RangeError) end end |