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/core/io | |
parent | a06301b103371b0b7da8eaca26ba744961769f99 (diff) |
Update to ruby/spec@875a09e
Diffstat (limited to 'spec/ruby/core/io')
65 files changed, 230 insertions, 191 deletions
diff --git a/spec/ruby/core/io/advise_spec.rb b/spec/ruby/core/io/advise_spec.rb index 81d5a49849..59469fa164 100644 --- a/spec/ruby/core/io/advise_spec.rb +++ b/spec/ruby/core/io/advise_spec.rb @@ -12,37 +12,37 @@ describe "IO#advise" do end it "raises a TypeError if advise is not a Symbol" do - lambda { + -> { @io.advise("normal") }.should raise_error(TypeError) end it "raises a TypeError if offset cannot be coerced to an Integer" do - lambda { + -> { @io.advise(:normal, "wat") }.should raise_error(TypeError) end it "raises a TypeError if len cannot be coerced to an Integer" do - lambda { + -> { @io.advise(:normal, 0, "wat") }.should raise_error(TypeError) end it "raises a RangeError if offset is too big" do - lambda { + -> { @io.advise(:normal, 10 ** 32) }.should raise_error(RangeError) end it "raises a RangeError if len is too big" do - lambda { + -> { @io.advise(:normal, 0, 10 ** 32) }.should raise_error(RangeError) end it "raises a NotImplementedError if advise is not recognized" do - lambda{ + ->{ @io.advise(:foo) }.should raise_error(NotImplementedError) end @@ -92,6 +92,6 @@ describe "IO#advise" do it "raises an IOError if the stream is closed" do @io.close - lambda { @io.advise(:normal) }.should raise_error(IOError) + -> { @io.advise(:normal) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/binmode_spec.rb b/spec/ruby/core/io/binmode_spec.rb index cc10e297dd..b698777cad 100644 --- a/spec/ruby/core/io/binmode_spec.rb +++ b/spec/ruby/core/io/binmode_spec.rb @@ -17,7 +17,7 @@ describe "IO#binmode" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.binmode }.should raise_error(IOError) + -> { IOSpecs.closed_io.binmode }.should raise_error(IOError) end it "sets external encoding to binary" do diff --git a/spec/ruby/core/io/binread_spec.rb b/spec/ruby/core/io/binread_spec.rb index 961044da58..a3f752d8f9 100644 --- a/spec/ruby/core/io/binread_spec.rb +++ b/spec/ruby/core/io/binread_spec.rb @@ -38,10 +38,10 @@ describe "IO.binread" do end it "raises an ArgumentError when not passed a valid length" do - lambda { IO.binread @fname, -1 }.should raise_error(ArgumentError) + -> { IO.binread @fname, -1 }.should raise_error(ArgumentError) end it "raises an Errno::EINVAL when not passed a valid offset" do - lambda { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) + -> { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) end end diff --git a/spec/ruby/core/io/bytes_spec.rb b/spec/ruby/core/io/bytes_spec.rb index 2d2bd950f1..feeb493566 100644 --- a/spec/ruby/core/io/bytes_spec.rb +++ b/spec/ruby/core/io/bytes_spec.rb @@ -31,13 +31,13 @@ describe "IO#bytes" do it "raises an IOError on closed stream" do enum = IOSpecs.closed_io.bytes - lambda { enum.first }.should raise_error(IOError) + -> { enum.first }.should raise_error(IOError) end it "raises an IOError on an enumerator for a stream that has been closed" do enum = @io.bytes enum.first.should == 86 @io.close - lambda { enum.first }.should raise_error(IOError) + -> { enum.first }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/close_on_exec_spec.rb b/spec/ruby/core/io/close_on_exec_spec.rb index d6ba3c3cef..f837bb56af 100644 --- a/spec/ruby/core/io/close_on_exec_spec.rb +++ b/spec/ruby/core/io/close_on_exec_spec.rb @@ -42,7 +42,7 @@ describe "IO#close_on_exec=" do it "raises IOError if called on a closed IO" do @io.close - lambda { @io.close_on_exec = true }.should raise_error(IOError) + -> { @io.close_on_exec = true }.should raise_error(IOError) end it "returns nil" do @@ -74,7 +74,7 @@ describe "IO#close_on_exec?" do it "raises IOError if called on a closed IO" do @io.close - lambda { @io.close_on_exec? }.should raise_error(IOError) + -> { @io.close_on_exec? }.should raise_error(IOError) end end end diff --git a/spec/ruby/core/io/close_read_spec.rb b/spec/ruby/core/io/close_read_spec.rb index 9783cb252a..6fa4fc8ff8 100644 --- a/spec/ruby/core/io/close_read_spec.rb +++ b/spec/ruby/core/io/close_read_spec.rb @@ -16,7 +16,7 @@ describe "IO#close_read" do it "closes the read end of a duplex I/O stream" do @io.close_read - lambda { @io.read }.should raise_error(IOError) + -> { @io.read }.should raise_error(IOError) end it "does nothing on subsequent invocations" do @@ -28,14 +28,14 @@ describe "IO#close_read" do it "allows subsequent invocation of close" do @io.close_read - lambda { @io.close }.should_not raise_error + -> { @io.close }.should_not raise_error end it "raises an IOError if the stream is writable and not duplexed" do io = File.open @path, 'w' begin - lambda { io.close_read }.should raise_error(IOError) + -> { io.close_read }.should raise_error(IOError) ensure io.close unless io.closed? end diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb index b7aa2276d1..21bba32cd8 100644 --- a/spec/ruby/core/io/close_spec.rb +++ b/spec/ruby/core/io/close_spec.rb @@ -23,19 +23,19 @@ describe "IO#close" do it "raises an IOError reading from a closed IO" do @io.close - lambda { @io.read }.should raise_error(IOError) + -> { @io.read }.should raise_error(IOError) end it "raises an IOError writing to a closed IO" do @io.close - lambda { @io.write "data" }.should raise_error(IOError) + -> { @io.write "data" }.should raise_error(IOError) end it 'does not close the stream if autoclose is false' do other_io = IO.new(@io.fileno) other_io.autoclose = false other_io.close - lambda { @io.write "data" }.should_not raise_error(IOError) + -> { @io.write "data" }.should_not raise_error(IOError) end it "does nothing if already closed" do @@ -49,7 +49,7 @@ describe "IO#close" do read_io, write_io = IO.pipe going_to_read = false thread = Thread.new do - lambda do + -> do going_to_read = true read_io.read end.should raise_error(IOError, 'stream closed in another thread') @@ -72,7 +72,7 @@ describe "IO#close on an IO.popen stream" do io.close - lambda { io.pid }.should raise_error(IOError) + -> { io.pid }.should raise_error(IOError) end it "sets $?" do diff --git a/spec/ruby/core/io/close_write_spec.rb b/spec/ruby/core/io/close_write_spec.rb index 8643659025..75e1577654 100644 --- a/spec/ruby/core/io/close_write_spec.rb +++ b/spec/ruby/core/io/close_write_spec.rb @@ -15,7 +15,7 @@ describe "IO#close_write" do it "closes the write end of a duplex I/O stream" do @io.close_write - lambda { @io.write "attempt to write" }.should raise_error(IOError) + -> { @io.write "attempt to write" }.should raise_error(IOError) end it "does nothing on subsequent invocations" do @@ -27,14 +27,14 @@ describe "IO#close_write" do it "allows subsequent invocation of close" do @io.close_write - lambda { @io.close }.should_not raise_error + -> { @io.close }.should_not raise_error end it "raises an IOError if the stream is readable and not duplexed" do io = File.open @path, 'w+' begin - lambda { io.close_write }.should raise_error(IOError) + -> { io.close_write }.should raise_error(IOError) ensure io.close unless io.closed? end diff --git a/spec/ruby/core/io/copy_stream_spec.rb b/spec/ruby/core/io/copy_stream_spec.rb index 622be0818b..c541e96e14 100644 --- a/spec/ruby/core/io/copy_stream_spec.rb +++ b/spec/ruby/core/io/copy_stream_spec.rb @@ -31,7 +31,7 @@ describe :io_copy_stream_to_file, shared: true do obj = mock("io_copy_stream_to") obj.should_receive(:to_path).and_return(1) - lambda { IO.copy_stream(@object.from, obj) }.should raise_error(TypeError) + -> { IO.copy_stream(@object.from, obj) }.should raise_error(TypeError) end end @@ -71,7 +71,7 @@ describe :io_copy_stream_to_io, shared: true do it "raises an IOError if the destination IO is not open for writing" do @to_io.close @to_io = new_io @to_name, "r" - lambda { IO.copy_stream @object.from, @to_io }.should raise_error(IOError) + -> { IO.copy_stream @object.from, @to_io }.should raise_error(IOError) end it "does not close the destination IO" do @@ -125,7 +125,7 @@ describe "IO.copy_stream" do it "raises an IOError if the source IO is not open for reading" do @from_io.close @from_io = new_io @from_bigfile, "a" - lambda { IO.copy_stream @from_io, @to_name }.should raise_error(IOError) + -> { IO.copy_stream @from_io, @to_name }.should raise_error(IOError) end it "does not close the source IO" do @@ -183,7 +183,7 @@ describe "IO.copy_stream" do obj = mock("io_copy_stream_from") obj.should_receive(:to_path).and_return(1) - lambda { IO.copy_stream(obj, @to_name) }.should raise_error(TypeError) + -> { IO.copy_stream(obj, @to_name) }.should raise_error(TypeError) end describe "to a file name" do @@ -222,7 +222,7 @@ describe "IO.copy_stream" do platform_is_not :windows do it "raises an error when an offset is specified" do - lambda { IO.copy_stream(@from_io, @to_name, 8, 4) }.should raise_error(Errno::ESPIPE) + -> { IO.copy_stream(@from_io, @to_name, 8, 4) }.should raise_error(Errno::ESPIPE) end end diff --git a/spec/ruby/core/io/dup_spec.rb b/spec/ruby/core/io/dup_spec.rb index c88d109ec9..de32c5e347 100644 --- a/spec/ruby/core/io/dup_spec.rb +++ b/spec/ruby/core/io/dup_spec.rb @@ -49,7 +49,7 @@ end it "allows closing the new IO without affecting the original" do @i.close - lambda { @f.gets }.should_not raise_error(Exception) + -> { @f.gets }.should_not raise_error(Exception) @i.closed?.should == true @f.closed?.should == false @@ -57,14 +57,14 @@ end it "allows closing the original IO without affecting the new one" do @f.close - lambda { @i.gets }.should_not raise_error(Exception) + -> { @i.gets }.should_not raise_error(Exception) @i.closed?.should == false @f.closed?.should == true end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.dup }.should raise_error(IOError) + -> { IOSpecs.closed_io.dup }.should raise_error(IOError) end it "always sets the close-on-exec flag for the new IO object" do diff --git a/spec/ruby/core/io/each_byte_spec.rb b/spec/ruby/core/io/each_byte_spec.rb index 9cdb1ac0c9..ea618e8c0c 100644 --- a/spec/ruby/core/io/each_byte_spec.rb +++ b/spec/ruby/core/io/each_byte_spec.rb @@ -12,7 +12,7 @@ describe "IO#each_byte" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.each_byte {} }.should raise_error(IOError) + -> { IOSpecs.closed_io.each_byte {} }.should raise_error(IOError) end it "yields each byte" do diff --git a/spec/ruby/core/io/each_codepoint_spec.rb b/spec/ruby/core/io/each_codepoint_spec.rb index 19824c38e4..cddc6b4662 100644 --- a/spec/ruby/core/io/each_codepoint_spec.rb +++ b/spec/ruby/core/io/each_codepoint_spec.rb @@ -38,6 +38,6 @@ describe "IO#each_codepoint" do end it "raises an exception at incomplete character before EOF when conversion takes place" do - lambda { @io.each_codepoint {} }.should raise_error(ArgumentError) + -> { @io.each_codepoint {} }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/io/eof_spec.rb b/spec/ruby/core/io/eof_spec.rb index 3ab389af09..8fd3c37132 100644 --- a/spec/ruby/core/io/eof_spec.rb +++ b/spec/ruby/core/io/eof_spec.rb @@ -16,7 +16,7 @@ describe "IO#eof?" do end it "raises IOError on stream not opened for reading" do - lambda do + -> do File.open(@name, "w") { |f| f.eof? } end.should raise_error(IOError) end @@ -67,12 +67,12 @@ describe "IO#eof?" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.eof? }.should raise_error(IOError) + -> { IOSpecs.closed_io.eof? }.should raise_error(IOError) end it "raises IOError on stream closed for reading by close_read" do @io.close_read - lambda { @io.eof? }.should raise_error(IOError) + -> { @io.eof? }.should raise_error(IOError) end it "returns true on one-byte stream after single-byte read" do diff --git a/spec/ruby/core/io/fcntl_spec.rb b/spec/ruby/core/io/fcntl_spec.rb index 049f92c0a2..30b4876fe3 100644 --- a/spec/ruby/core/io/fcntl_spec.rb +++ b/spec/ruby/core/io/fcntl_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "IO#fcntl" do it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.fcntl(5, 5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.fcntl(5, 5) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/fileno_spec.rb b/spec/ruby/core/io/fileno_spec.rb index d7aff99e72..647609bf42 100644 --- a/spec/ruby/core/io/fileno_spec.rb +++ b/spec/ruby/core/io/fileno_spec.rb @@ -7,6 +7,6 @@ describe "IO#fileno" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.fileno }.should raise_error(IOError) + -> { IOSpecs.closed_io.fileno }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/flush_spec.rb b/spec/ruby/core/io/flush_spec.rb index c81ff74a69..34cf42c425 100644 --- a/spec/ruby/core/io/flush_spec.rb +++ b/spec/ruby/core/io/flush_spec.rb @@ -3,6 +3,35 @@ require_relative 'fixtures/classes' describe "IO#flush" do it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.flush }.should raise_error(IOError) + -> { IOSpecs.closed_io.flush }.should raise_error(IOError) + end + + describe "on a pipe" do + before :each do + @r, @w = IO.pipe + end + + after :each do + @r.close + begin + @w.close + rescue Errno::EPIPE + end + end + + # [ruby-core:90895] MJIT worker may leave fd open in a forked child. + # For instance, MJIT creates a worker before @r.close with fork(), @r.close happens, + # and the MJIT worker keeps the pipe open until the worker execve(). + # TODO: consider acquiring GVL from MJIT worker. + guard_not -> { defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? } do + it "raises Errno::EPIPE if sync=false and the read end is closed" do + @w.sync = false + @w.write "foo" + @r.close + + -> { @w.flush }.should raise_error(Errno::EPIPE, /Broken pipe/) + -> { @w.close }.should raise_error(Errno::EPIPE, /Broken pipe/) + end + end end end diff --git a/spec/ruby/core/io/fsync_spec.rb b/spec/ruby/core/io/fsync_spec.rb index 0261939631..6e6123de94 100644 --- a/spec/ruby/core/io/fsync_spec.rb +++ b/spec/ruby/core/io/fsync_spec.rb @@ -12,7 +12,7 @@ describe "IO#fsync" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.fsync }.should raise_error(IOError) + -> { IOSpecs.closed_io.fsync }.should raise_error(IOError) end it "writes the buffered data to permanent storage" do diff --git a/spec/ruby/core/io/getbyte_spec.rb b/spec/ruby/core/io/getbyte_spec.rb index 6b665029d6..6ba8f0a3e0 100644 --- a/spec/ruby/core/io/getbyte_spec.rb +++ b/spec/ruby/core/io/getbyte_spec.rb @@ -23,7 +23,7 @@ describe "IO#getbyte" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.getbyte }.should raise_error(IOError) + -> { IOSpecs.closed_io.getbyte }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/getc_spec.rb b/spec/ruby/core/io/getc_spec.rb index 7c1c18cd90..3949b5cb28 100644 --- a/spec/ruby/core/io/getc_spec.rb +++ b/spec/ruby/core/io/getc_spec.rb @@ -23,7 +23,7 @@ describe "IO#getc" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.getc }.should raise_error(IOError) + -> { IOSpecs.closed_io.getc }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb index 371c1c3d3b..8f6ec0dfc7 100644 --- a/spec/ruby/core/io/gets_spec.rb +++ b/spec/ruby/core/io/gets_spec.rb @@ -30,7 +30,7 @@ describe "IO#gets" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.gets }.should raise_error(IOError) + -> { IOSpecs.closed_io.gets }.should raise_error(IOError) end describe "with no separator" do @@ -156,11 +156,11 @@ describe "IO#gets" do end it "raises an IOError if the stream is opened for append only" do - lambda { File.open(@name, "a:utf-8") { |f| f.gets } }.should raise_error(IOError) + -> { File.open(@name, "a:utf-8") { |f| f.gets } }.should raise_error(IOError) end it "raises an IOError if the stream is opened for writing only" do - lambda { File.open(@name, "w:utf-8") { |f| f.gets } }.should raise_error(IOError) + -> { File.open(@name, "w:utf-8") { |f| f.gets } }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/initialize_spec.rb b/spec/ruby/core/io/initialize_spec.rb index 4858e0360c..c8f3faf110 100644 --- a/spec/ruby/core/io/initialize_spec.rb +++ b/spec/ruby/core/io/initialize_spec.rb @@ -28,22 +28,22 @@ describe "IO#initialize" do end it "raises a TypeError when passed an IO" do - lambda { @io.send :initialize, STDOUT, 'w' }.should raise_error(TypeError) + -> { @io.send :initialize, STDOUT, 'w' }.should raise_error(TypeError) end it "raises a TypeError when passed nil" do - lambda { @io.send :initialize, nil, 'w' }.should raise_error(TypeError) + -> { @io.send :initialize, nil, 'w' }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { @io.send :initialize, "4", 'w' }.should raise_error(TypeError) + -> { @io.send :initialize, "4", 'w' }.should raise_error(TypeError) end it "raises IOError on closed stream" do - lambda { @io.send :initialize, IOSpecs.closed_io.fileno }.should raise_error(IOError) + -> { @io.send :initialize, IOSpecs.closed_io.fileno }.should raise_error(IOError) end it "raises an Errno::EBADF when given an invalid file descriptor" do - lambda { @io.send :initialize, -1, 'w' }.should raise_error(Errno::EBADF) + -> { @io.send :initialize, -1, 'w' }.should raise_error(Errno::EBADF) end end diff --git a/spec/ruby/core/io/ioctl_spec.rb b/spec/ruby/core/io/ioctl_spec.rb index 0f2b67ac44..e819a217a8 100644 --- a/spec/ruby/core/io/ioctl_spec.rb +++ b/spec/ruby/core/io/ioctl_spec.rb @@ -4,7 +4,7 @@ require_relative 'fixtures/classes' describe "IO#ioctl" do platform_is_not :windows do it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.ioctl(5, 5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.ioctl(5, 5) }.should raise_error(IOError) end end @@ -22,7 +22,7 @@ describe "IO#ioctl" do it "raises an Errno error when ioctl fails" do File.open(__FILE__, 'r') do |f| - lambda { + -> { # TIOCGWINSZ in /usr/include/asm-generic/ioctls.h f.ioctl 0x5413, nil }.should raise_error(Errno::ENOTTY) diff --git a/spec/ruby/core/io/lineno_spec.rb b/spec/ruby/core/io/lineno_spec.rb index 322e60d643..3d1b2275cc 100644 --- a/spec/ruby/core/io/lineno_spec.rb +++ b/spec/ruby/core/io/lineno_spec.rb @@ -11,7 +11,7 @@ describe "IO#lineno" do end it "raises an IOError on a closed stream" do - lambda { IOSpecs.closed_io.lineno }.should raise_error(IOError) + -> { IOSpecs.closed_io.lineno }.should raise_error(IOError) end it "returns the current line number" do @@ -37,7 +37,7 @@ describe "IO#lineno=" do end it "raises an IOError on a closed stream" do - lambda { IOSpecs.closed_io.lineno = 5 }.should raise_error(IOError) + -> { IOSpecs.closed_io.lineno = 5 }.should raise_error(IOError) end it "calls #to_int on a non-numeric argument" do @@ -57,7 +57,7 @@ describe "IO#lineno=" do end it "raises TypeError on nil argument" do - lambda { @io.lineno = nil }.should raise_error(TypeError) + -> { @io.lineno = nil }.should raise_error(TypeError) end it "sets the current line number to the given value" do diff --git a/spec/ruby/core/io/open_spec.rb b/spec/ruby/core/io/open_spec.rb index f26753cde7..94df5a5ef6 100644 --- a/spec/ruby/core/io/open_spec.rb +++ b/spec/ruby/core/io/open_spec.rb @@ -38,7 +38,7 @@ describe "IO.open" do end it "propagates an exception raised by #close that is not a StandardError" do - lambda do + -> do IO.open(@fd, "w") do |io| IOSpecs.io_mock(io, :close) do super() @@ -51,7 +51,7 @@ describe "IO.open" do end it "propagates an exception raised by #close that is a StandardError" do - lambda do + -> do IO.open(@fd, "w") do |io| IOSpecs.io_mock(io, :close) do super() diff --git a/spec/ruby/core/io/output_spec.rb b/spec/ruby/core/io/output_spec.rb index d3ec71c563..2aafb305f4 100644 --- a/spec/ruby/core/io/output_spec.rb +++ b/spec/ruby/core/io/output_spec.rb @@ -3,24 +3,24 @@ require_relative 'fixtures/classes' describe "IO#<<" do it "writes an object to the IO stream" do - lambda { + -> { $stderr << "Oh noes, an error!" }.should output_to_fd("Oh noes, an error!", $stderr) end it "calls #to_s on the object to print it" do - lambda { + -> { $stderr << 1337 }.should output_to_fd("1337", $stderr) end it "raises an error if the stream is closed" do io = IOSpecs.closed_io - lambda { io << "test" }.should raise_error(IOError) + -> { io << "test" }.should raise_error(IOError) end it "returns self" do - lambda { + -> { ($stderr << "to_stderr").should == $stderr }.should output(nil, "to_stderr") end diff --git a/spec/ruby/core/io/pid_spec.rb b/spec/ruby/core/io/pid_spec.rb index 97b8a8529d..bc09fe7c3b 100644 --- a/spec/ruby/core/io/pid_spec.rb +++ b/spec/ruby/core/io/pid_spec.rb @@ -30,6 +30,6 @@ describe "IO#pid" do it "raises an IOError on closed stream" do @io.close - lambda { @io.pid }.should raise_error(IOError) + -> { @io.pid }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/pipe_spec.rb b/spec/ruby/core/io/pipe_spec.rb index 005f60fab6..5b2f18d836 100644 --- a/spec/ruby/core/io/pipe_spec.rb +++ b/spec/ruby/core/io/pipe_spec.rb @@ -50,7 +50,7 @@ describe "IO.pipe" do it "closes both IO objects when the block raises" do r = w = nil - lambda do + -> do IO.pipe do |_r, _w| r = _r w = _w diff --git a/spec/ruby/core/io/popen_spec.rb b/spec/ruby/core/io/popen_spec.rb index 289bb076e4..622b3a9394 100644 --- a/spec/ruby/core/io/popen_spec.rb +++ b/spec/ruby/core/io/popen_spec.rb @@ -22,7 +22,7 @@ describe "IO.popen" do it "raises IOError when writing a read-only pipe" do @io = IO.popen(ruby_cmd('puts "foo"'), "r") - lambda { @io.write('bar') }.should raise_error(IOError) + -> { @io.write('bar') }.should raise_error(IOError) @io.read.should == "foo\n" end end @@ -55,7 +55,7 @@ describe "IO.popen" do it "raises IOError when reading a write-only pipe" do @io = IO.popen(ruby_cmd('IO.copy_stream(STDIN,STDOUT)'), "w") - lambda { @io.read }.should raise_error(IOError) + -> { @io.read }.should raise_error(IOError) end it "reads and writes a read/write pipe" do diff --git a/spec/ruby/core/io/pread_spec.rb b/spec/ruby/core/io/pread_spec.rb index b5b516fa53..bfe6472fef 100644 --- a/spec/ruby/core/io/pread_spec.rb +++ b/spec/ruby/core/io/pread_spec.rb @@ -33,19 +33,19 @@ ruby_version_is "2.5" do end it "raises EOFError if end-of-file is reached" do - lambda { @file.pread(1, 10) }.should raise_error(EOFError) + -> { @file.pread(1, 10) }.should raise_error(EOFError) end it "raises IOError when file is not open in read mode" do File.open(@fname, "w") do |file| - lambda { file.pread(1, 1) }.should raise_error(IOError) + -> { file.pread(1, 1) }.should raise_error(IOError) end end it "raises IOError when file is closed" do file = File.open(@fname, "r+") file.close - lambda { file.pread(1, 1) }.should raise_error(IOError) + -> { file.pread(1, 1) }.should raise_error(IOError) end end end diff --git a/spec/ruby/core/io/print_spec.rb b/spec/ruby/core/io/print_spec.rb index 0dd48344ce..2021cd5420 100644 --- a/spec/ruby/core/io/print_spec.rb +++ b/spec/ruby/core/io/print_spec.rb @@ -48,6 +48,6 @@ describe IO, "#print" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.print("stuff") }.should raise_error(IOError) + -> { IOSpecs.closed_io.print("stuff") }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/printf_spec.rb b/spec/ruby/core/io/printf_spec.rb index be4e5c339e..baa00f14ce 100644 --- a/spec/ruby/core/io/printf_spec.rb +++ b/spec/ruby/core/io/printf_spec.rb @@ -27,6 +27,6 @@ describe "IO#printf" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.printf("stuff") }.should raise_error(IOError) + -> { IOSpecs.closed_io.printf("stuff") }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/puts_spec.rb b/spec/ruby/core/io/puts_spec.rb index e8d599730f..3e4b877b7f 100644 --- a/spec/ruby/core/io/puts_spec.rb +++ b/spec/ruby/core/io/puts_spec.rb @@ -25,7 +25,7 @@ describe "IO#puts" do end it "writes just a newline when given just a newline" do - lambda { $stdout.puts "\n" }.should output_to_fd("\n", STDOUT) + -> { $stdout.puts "\n" }.should output_to_fd("\n", STDOUT) end it "writes empty string with a newline when given nil as an arg" do @@ -111,7 +111,7 @@ describe "IO#puts" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.puts("stuff") }.should raise_error(IOError) + -> { IOSpecs.closed_io.puts("stuff") }.should raise_error(IOError) end it "writes crlf when IO is opened with newline: :crlf" do diff --git a/spec/ruby/core/io/pwrite_spec.rb b/spec/ruby/core/io/pwrite_spec.rb index fd3d1b98e9..929ed08698 100644 --- a/spec/ruby/core/io/pwrite_spec.rb +++ b/spec/ruby/core/io/pwrite_spec.rb @@ -31,14 +31,14 @@ ruby_version_is "2.5" do it "raises IOError when file is not open in write mode" do File.open(@fname, "r") do |file| - lambda { file.pwrite("foo", 1) }.should raise_error(IOError) + -> { file.pwrite("foo", 1) }.should raise_error(IOError) end end it "raises IOError when file is closed" do file = File.open(@fname, "w+") file.close - lambda { file.pwrite("foo", 1) }.should raise_error(IOError) + -> { file.pwrite("foo", 1) }.should raise_error(IOError) end end end diff --git a/spec/ruby/core/io/read_nonblock_spec.rb b/spec/ruby/core/io/read_nonblock_spec.rb index 59f5064922..63ccab5a44 100644 --- a/spec/ruby/core/io/read_nonblock_spec.rb +++ b/spec/ruby/core/io/read_nonblock_spec.rb @@ -12,7 +12,7 @@ describe "IO#read_nonblock" do end it "raises an exception extending IO::WaitReadable when there is no data" do - lambda { @read.read_nonblock(5) }.should raise_error(IO::WaitReadable) { |e| + -> { @read.read_nonblock(5) }.should raise_error(IO::WaitReadable) { |e| platform_is_not :windows do e.should be_kind_of(Errno::EAGAIN) end @@ -85,7 +85,7 @@ describe "IO#read_nonblock" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.read_nonblock(5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.read_nonblock(5) }.should raise_error(IOError) end it "raises EOFError when the end is reached" do @@ -94,6 +94,6 @@ describe "IO#read_nonblock" do @read.read_nonblock(5) - lambda { @read.read_nonblock(5) }.should raise_error(EOFError) + -> { @read.read_nonblock(5) }.should raise_error(EOFError) end end diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index e005e14fdf..267d840cd3 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -36,11 +36,11 @@ describe "IO.read" do end it "raises an IOError if the options Hash specifies write mode" do - lambda { IO.read(@fname, 3, 0, {mode: "w"}) }.should raise_error(IOError) + -> { IO.read(@fname, 3, 0, {mode: "w"}) }.should raise_error(IOError) end it "raises an IOError if the options Hash specifies append only mode" do - lambda { IO.read(@fname, {mode: "a"}) }.should raise_error(IOError) + -> { IO.read(@fname, {mode: "a"}) }.should raise_error(IOError) end it "reads the file if the options Hash includes read mode" do @@ -79,20 +79,20 @@ describe "IO.read" do it "raises an Errno::ENOENT when the requested file does not exist" do rm_r @fname - lambda { IO.read @fname }.should raise_error(Errno::ENOENT) + -> { IO.read @fname }.should raise_error(Errno::ENOENT) end it "raises a TypeError when not passed a String type" do - lambda { IO.read nil }.should raise_error(TypeError) + -> { IO.read nil }.should raise_error(TypeError) end it "raises an ArgumentError when not passed a valid length" do - lambda { IO.read @fname, -1 }.should raise_error(ArgumentError) + -> { IO.read @fname, -1 }.should raise_error(ArgumentError) end it "raises an Errno::EINVAL when not passed a valid offset" do - lambda { IO.read @fname, 0, -1 }.should raise_error(Errno::EINVAL) - lambda { IO.read @fname, -1, -1 }.should raise_error(Errno::EINVAL) + -> { IO.read @fname, 0, -1 }.should raise_error(Errno::EINVAL) + -> { IO.read @fname, -1, -1 }.should raise_error(Errno::EINVAL) end it "uses the external encoding specified via the :external_encoding option" do @@ -137,7 +137,7 @@ describe "IO.read from a pipe" do platform_is_not :windows do it "raises Errno::ESPIPE if passed an offset" do - lambda { + -> { IO.read("|sh -c 'echo hello'", 1, 1) }.should raise_error(Errno::ESPIPE) end @@ -148,7 +148,7 @@ quarantine! do # The process tried to write to a nonexistent pipe. # TODO: It should raise Errno::ESPIPE on Windows as well # once https://bugs.ruby-lang.org/issues/12230 is fixed. it "raises Errno::EINVAL if passed an offset" do - lambda { + -> { IO.read("|cmd.exe /C echo hello", 1, 1) }.should raise_error(Errno::EINVAL) end @@ -301,7 +301,7 @@ describe "IO#read" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.read }.should raise_error(IOError) + -> { IOSpecs.closed_io.read }.should raise_error(IOError) end diff --git a/spec/ruby/core/io/readbyte_spec.rb b/spec/ruby/core/io/readbyte_spec.rb index eb25975f58..14426c28ac 100644 --- a/spec/ruby/core/io/readbyte_spec.rb +++ b/spec/ruby/core/io/readbyte_spec.rb @@ -17,7 +17,7 @@ describe "IO#readbyte" do it "raises EOFError on EOF" do @io.seek(999999) - lambda do + -> do @io.readbyte end.should raise_error EOFError end diff --git a/spec/ruby/core/io/readchar_spec.rb b/spec/ruby/core/io/readchar_spec.rb index 74f78b5a6e..b5f762a846 100644 --- a/spec/ruby/core/io/readchar_spec.rb +++ b/spec/ruby/core/io/readchar_spec.rb @@ -21,11 +21,11 @@ describe "IO#readchar" do it "raises an EOFError when invoked at the end of the stream" do @io.read - lambda { @io.readchar }.should raise_error(EOFError) + -> { @io.readchar }.should raise_error(EOFError) end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.readchar }.should raise_error(IOError) + -> { IOSpecs.closed_io.readchar }.should raise_error(IOError) end end @@ -39,6 +39,6 @@ describe "IO#readchar" do end it "raises EOFError on empty stream" do - lambda { @io.readchar }.should raise_error(EOFError) + -> { @io.readchar }.should raise_error(EOFError) end end diff --git a/spec/ruby/core/io/readline_spec.rb b/spec/ruby/core/io/readline_spec.rb index 3eae6bfa47..7cb1601816 100644 --- a/spec/ruby/core/io/readline_spec.rb +++ b/spec/ruby/core/io/readline_spec.rb @@ -29,11 +29,11 @@ describe "IO#readline" do it "raises EOFError on end of stream" do IOSpecs.lines.length.times { @io.readline } - lambda { @io.readline }.should raise_error(EOFError) + -> { @io.readline }.should raise_error(EOFError) end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.readline }.should raise_error(IOError) + -> { IOSpecs.closed_io.readline }.should raise_error(IOError) end it "assigns the returned line to $_" do diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb index 5a7e9b5aa8..0d4f002972 100644 --- a/spec/ruby/core/io/readlines_spec.rb +++ b/spec/ruby/core/io/readlines_spec.rb @@ -17,7 +17,7 @@ describe "IO#readlines" do it "raises an IOError if the stream is closed" do @io.close - lambda { @io.readlines }.should raise_error(IOError) + -> { @io.readlines }.should raise_error(IOError) end describe "when passed no arguments" do @@ -138,13 +138,13 @@ describe "IO#readlines" do end it "raises an IOError if the stream is opened for append only" do - lambda do + -> do File.open(@name, "a:utf-8") { |f| f.readlines } end.should raise_error(IOError) end it "raises an IOError if the stream is opened for write only" do - lambda do + -> do File.open(@name, "w:utf-8") { |f| f.readlines } end.should raise_error(IOError) end diff --git a/spec/ruby/core/io/readpartial_spec.rb b/spec/ruby/core/io/readpartial_spec.rb index 1ab01dcf49..2b33a0d5b1 100644 --- a/spec/ruby/core/io/readpartial_spec.rb +++ b/spec/ruby/core/io/readpartial_spec.rb @@ -15,10 +15,10 @@ describe "IO#readpartial" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.readpartial(10) }.should raise_error(IOError) + -> { IOSpecs.closed_io.readpartial(10) }.should raise_error(IOError) @rd.close - lambda { @rd.readpartial(10) }.should raise_error(IOError) + -> { @rd.readpartial(10) }.should raise_error(IOError) end it "reads at most the specified number of bytes" do @@ -70,23 +70,23 @@ describe "IO#readpartial" do @wr.write("abc") @wr.close @rd.readpartial(10).should == 'abc' - lambda { @rd.readpartial(10) }.should raise_error(EOFError) + -> { @rd.readpartial(10) }.should raise_error(EOFError) end it "discards the existing buffer content upon error" do buffer = 'hello' @wr.close - lambda { @rd.readpartial(1, buffer) }.should raise_error(EOFError) + -> { @rd.readpartial(1, buffer) }.should raise_error(EOFError) buffer.should be_empty end it "raises IOError if the stream is closed" do @wr.close - lambda { @rd.readpartial(1) }.should raise_error(IOError) + -> { @rd.readpartial(1) }.should raise_error(IOError) end it "raises ArgumentError if the negative argument is provided" do - lambda { @rd.readpartial(-1) }.should raise_error(ArgumentError) + -> { @rd.readpartial(-1) }.should raise_error(ArgumentError) end it "immediately returns an empty string if the length argument is 0" do diff --git a/spec/ruby/core/io/reopen_spec.rb b/spec/ruby/core/io/reopen_spec.rb index 84c23472b7..133ff03ea5 100644 --- a/spec/ruby/core/io/reopen_spec.rb +++ b/spec/ruby/core/io/reopen_spec.rb @@ -33,29 +33,29 @@ describe "IO#reopen" do it "raises an IOError if the object returned by #to_io is closed" do obj = mock("io") obj.should_receive(:to_io).and_return(IOSpecs.closed_io) - lambda { @io.reopen obj }.should raise_error(IOError) + -> { @io.reopen obj }.should raise_error(IOError) end it "raises a TypeError if #to_io does not return an IO instance" do obj = mock("io") obj.should_receive(:to_io).and_return("something else") - lambda { @io.reopen obj }.should raise_error(TypeError) + -> { @io.reopen obj }.should raise_error(TypeError) end it "raises an IOError when called on a closed stream with an object" do @io.close obj = mock("io") obj.should_not_receive(:to_io) - lambda { @io.reopen(STDOUT) }.should raise_error(IOError) + -> { @io.reopen(STDOUT) }.should raise_error(IOError) end it "raises an IOError if the IO argument is closed" do - lambda { @io.reopen(IOSpecs.closed_io) }.should raise_error(IOError) + -> { @io.reopen(IOSpecs.closed_io) }.should raise_error(IOError) end it "raises an IOError when called on a closed stream with an IO" do @io.close - lambda { @io.reopen(STDOUT) }.should raise_error(IOError) + -> { @io.reopen(STDOUT) }.should raise_error(IOError) end end @@ -188,7 +188,7 @@ describe "IO#reopen with a String" do it "raises an Errno::ENOENT if the file does not exist and the IO is not opened in write mode" do @io = new_io @name, "r" - lambda { @io.reopen(@other_name) }.should raise_error(Errno::ENOENT) + -> { @io.reopen(@other_name) }.should raise_error(Errno::ENOENT) end end diff --git a/spec/ruby/core/io/rewind_spec.rb b/spec/ruby/core/io/rewind_spec.rb index d1ec7a69c7..954d56d30c 100644 --- a/spec/ruby/core/io/rewind_spec.rb +++ b/spec/ruby/core/io/rewind_spec.rb @@ -33,6 +33,6 @@ describe "IO#rewind" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.rewind }.should raise_error(IOError) + -> { IOSpecs.closed_io.rewind }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/seek_spec.rb b/spec/ruby/core/io/seek_spec.rb index 9978d7c0e7..7e9c308272 100644 --- a/spec/ruby/core/io/seek_spec.rb +++ b/spec/ruby/core/io/seek_spec.rb @@ -17,7 +17,7 @@ describe "IO#seek" do end it "moves the read position relative to the current position with SEEK_CUR" do - lambda { @io.seek(-1) }.should raise_error(Errno::EINVAL) + -> { @io.seek(-1) }.should raise_error(Errno::EINVAL) @io.seek(10, IO::SEEK_CUR) @io.readline.should == "igne une.\n" @io.seek(-5, IO::SEEK_CUR) diff --git a/spec/ruby/core/io/select_spec.rb b/spec/ruby/core/io/select_spec.rb index e69669efd2..4603c1fbbc 100644 --- a/spec/ruby/core/io/select_spec.rb +++ b/spec/ruby/core/io/select_spec.rb @@ -80,28 +80,28 @@ describe "IO.select" do end it "raises TypeError if supplied objects are not IO" do - lambda { IO.select([Object.new]) }.should raise_error(TypeError) - lambda { IO.select(nil, [Object.new]) }.should raise_error(TypeError) + -> { IO.select([Object.new]) }.should raise_error(TypeError) + -> { IO.select(nil, [Object.new]) }.should raise_error(TypeError) obj = mock("io") obj.should_receive(:to_io).any_number_of_times.and_return(nil) - lambda { IO.select([obj]) }.should raise_error(TypeError) - lambda { IO.select(nil, [obj]) }.should raise_error(TypeError) + -> { IO.select([obj]) }.should raise_error(TypeError) + -> { IO.select(nil, [obj]) }.should raise_error(TypeError) end it "raises a TypeError if the specified timeout value is not Numeric" do - lambda { IO.select([@rd], nil, nil, Object.new) }.should raise_error(TypeError) + -> { IO.select([@rd], nil, nil, Object.new) }.should raise_error(TypeError) end it "raises TypeError if the first three arguments are not Arrays" do - lambda { IO.select(Object.new)}.should raise_error(TypeError) - lambda { IO.select(nil, Object.new)}.should raise_error(TypeError) - lambda { IO.select(nil, nil, Object.new)}.should raise_error(TypeError) + -> { IO.select(Object.new)}.should raise_error(TypeError) + -> { IO.select(nil, Object.new)}.should raise_error(TypeError) + -> { IO.select(nil, nil, Object.new)}.should raise_error(TypeError) end it "raises an ArgumentError when passed a negative timeout" do - lambda { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError) + -> { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/io/shared/binwrite.rb b/spec/ruby/core/io/shared/binwrite.rb index 1a88442a3b..17682a1a93 100644 --- a/spec/ruby/core/io/shared/binwrite.rb +++ b/spec/ruby/core/io/shared/binwrite.rb @@ -68,7 +68,7 @@ describe :io_binwrite, shared: true do end it "raises an error if readonly mode is specified" do - lambda { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError) + -> { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError) end it "truncates if empty :opts provided and offset skipped" do diff --git a/spec/ruby/core/io/shared/chars.rb b/spec/ruby/core/io/shared/chars.rb index 7f2edd2b6d..266566f221 100644 --- a/spec/ruby/core/io/shared/chars.rb +++ b/spec/ruby/core/io/shared/chars.rb @@ -46,11 +46,11 @@ describe :io_chars, shared: true do end it "raises an IOError when an enumerator created on a closed stream is accessed" do - lambda { IOSpecs.closed_io.send(@method).first }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method).first }.should raise_error(IOError) end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/codepoints.rb b/spec/ruby/core/io/shared/codepoints.rb index a5062e7f79..6872846c1a 100644 --- a/spec/ruby/core/io/shared/codepoints.rb +++ b/spec/ruby/core/io/shared/codepoints.rb @@ -39,7 +39,7 @@ describe :io_codepoints, shared: true do it "raises an error if reading invalid sequence" do @io.pos = 60 # inside of a multibyte sequence - lambda { @enum.first }.should raise_error(ArgumentError) + -> { @enum.first }.should raise_error(ArgumentError) end it "does not change $_" do @@ -49,6 +49,6 @@ describe :io_codepoints, shared: true do end it "raises an IOError when self is not readable" do - lambda { IOSpecs.closed_io.send(@method).to_a }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method).to_a }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/each.rb b/spec/ruby/core/io/shared/each.rb index da562e03b1..0b2dfa3548 100644 --- a/spec/ruby/core/io/shared/each.rb +++ b/spec/ruby/core/io/shared/each.rb @@ -38,7 +38,7 @@ describe :io_each, shared: true do end it "raises an IOError when self is not readable" do - lambda { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) end it "makes line count accessible via lineno" do @@ -74,7 +74,7 @@ describe :io_each, shared: true do describe "when limit is 0" do it "raises an ArgumentError" do # must pass block so Enumerator is evaluated and raises - lambda { @io.send(@method, 0){} }.should raise_error(ArgumentError) + -> { @io.send(@method, 0){} }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb index f6069a4cdc..2101958170 100644 --- a/spec/ruby/core/io/shared/new.rb +++ b/spec/ruby/core/io/shared/new.rb @@ -115,14 +115,14 @@ describe :io_new, shared: true do end it "ignores the :encoding option when the :external_encoding option is present" do - lambda { + -> { @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1'}) }.should complain(/Ignoring encoding parameter/) @io.external_encoding.to_s.should == 'UTF-8' end it "ignores the :encoding option when the :internal_encoding option is present" do - lambda { + -> { @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1'}) }.should complain(/Ignoring encoding parameter/) @io.internal_encoding.to_s.should == 'IBM866' @@ -282,96 +282,96 @@ describe :io_new_errors, shared: true do end it "raises an Errno::EBADF if the file descriptor is not valid" do - lambda { IO.send(@method, -1, "w") }.should raise_error(Errno::EBADF) + -> { IO.send(@method, -1, "w") }.should raise_error(Errno::EBADF) end it "raises an IOError if passed a closed stream" do - lambda { IO.send(@method, IOSpecs.closed_io.fileno, 'w') }.should raise_error(IOError) + -> { IO.send(@method, IOSpecs.closed_io.fileno, 'w') }.should raise_error(IOError) end platform_is_not :windows do it "raises an Errno::EINVAL if the new mode is not compatible with the descriptor's current mode" do - lambda { IO.send(@method, @fd, "r") }.should raise_error(Errno::EINVAL) + -> { IO.send(@method, @fd, "r") }.should raise_error(Errno::EINVAL) end end it "raises ArgumentError if passed an empty mode string" do - lambda { IO.send(@method, @fd, "") }.should raise_error(ArgumentError) + -> { IO.send(@method, @fd, "") }.should raise_error(ArgumentError) end it "raises an error if passed modes two ways" do - lambda { + -> { IO.send(@method, @fd, "w", mode: "w") }.should raise_error(ArgumentError) end it "raises an error if passed encodings two ways" do - lambda { + -> { @io = IO.send(@method, @fd, 'w:ISO-8859-1', {encoding: 'ISO-8859-1'}) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, 'w:ISO-8859-1', {external_encoding: 'ISO-8859-1'}) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', {internal_encoding: 'ISO-8859-1'}) }.should raise_error(ArgumentError) end it "raises an error if passed matching binary/text mode two ways" do - lambda { + -> { @io = IO.send(@method, @fd, "wb", binmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", textmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wb", textmode: false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", binmode: false) }.should raise_error(ArgumentError) end it "raises an error if passed conflicting binary/text mode two ways" do - lambda { + -> { @io = IO.send(@method, @fd, "wb", binmode: false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", textmode: false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wb", textmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", binmode: true) }.should raise_error(ArgumentError) end it "raises an error when trying to set both binmode and textmode" do - lambda { + -> { @io = IO.send(@method, @fd, "w", textmode: true, binmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, File::Constants::WRONLY, textmode: true, binmode: true) }.should raise_error(ArgumentError) end it "raises ArgumentError if not passed a hash or nil for options" do - lambda { + -> { @io = IO.send(@method, @fd, 'w', false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, false, false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, nil, false) }.should raise_error(ArgumentError) end it "raises TypeError if passed a hash for mode and nil for options" do - lambda { + -> { @io = IO.send(@method, @fd, {mode: 'w'}, nil) }.should raise_error(TypeError) end diff --git a/spec/ruby/core/io/shared/pos.rb b/spec/ruby/core/io/shared/pos.rb index fef7ab2bf7..fb6d8087bc 100644 --- a/spec/ruby/core/io/shared/pos.rb +++ b/spec/ruby/core/io/shared/pos.rb @@ -19,7 +19,7 @@ describe :io_pos, shared: true do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send(@method) }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method) }.should raise_error(IOError) end it "resets #eof?" do @@ -62,11 +62,11 @@ describe :io_set_pos, shared: true do it "does not accept Bignums that don't fit in a C long" do File.open @fname do |io| - lambda { io.send @method, 2**128 }.should raise_error(RangeError) + -> { io.send @method, 2**128 }.should raise_error(RangeError) end end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send @method, 0 }.should raise_error(IOError) + -> { IOSpecs.closed_io.send @method, 0 }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/readlines.rb b/spec/ruby/core/io/shared/readlines.rb index 08d41e0a4c..9bc02da0bd 100644 --- a/spec/ruby/core/io/shared/readlines.rb +++ b/spec/ruby/core/io/shared/readlines.rb @@ -1,11 +1,11 @@ describe :io_readlines, shared: true do it "raises TypeError if the first parameter is nil" do - lambda { IO.send(@method, nil, &@object) }.should raise_error(TypeError) + -> { IO.send(@method, nil, &@object) }.should raise_error(TypeError) end it "raises an Errno::ENOENT if the file does not exist" do name = tmp("nonexistent.txt") - lambda { IO.send(@method, name, &@object) }.should raise_error(Errno::ENOENT) + -> { IO.send(@method, name, &@object) }.should raise_error(Errno::ENOENT) end it "yields a single string with entire content when the separator is nil" do @@ -98,7 +98,7 @@ describe :io_readlines_options_19, shared: true do describe "when passed name, object, object" do describe "when the first object is a Fixnum" do it "uses the second object as an options Hash" do - lambda do + -> do IO.send(@method, @filename, 10, mode: "w", &@object) end.should raise_error(IOError) end @@ -106,7 +106,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the second object to a Hash" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, 10, options, &@object) end.should raise_error(IOError) end @@ -126,7 +126,7 @@ describe :io_readlines_options_19, shared: true do end it "uses the second object as an options Hash" do - lambda do + -> do IO.send(@method, @filename, " ", mode: "w", &@object) end.should raise_error(IOError) end @@ -134,7 +134,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the second object to a Hash" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, " ", options, &@object) end.should raise_error(IOError) end @@ -161,7 +161,7 @@ describe :io_readlines_options_19, shared: true do end it "uses the second object as an options Hash" do - lambda do + -> do IO.send(@method, @filename, " ", mode: "w", &@object) end.should raise_error(IOError) end @@ -169,7 +169,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the second object to a Hash" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, " ", options, &@object) end.should raise_error(IOError) end @@ -201,7 +201,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the options object" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, " ", 10, options, &@object) end.should raise_error(IOError) end diff --git a/spec/ruby/core/io/shared/tty.rb b/spec/ruby/core/io/shared/tty.rb index 947b887f81..82a780a9f3 100644 --- a/spec/ruby/core/io/shared/tty.rb +++ b/spec/ruby/core/io/shared/tty.rb @@ -20,6 +20,6 @@ describe :io_tty, shared: true do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send @method }.should raise_error(IOError) + -> { IOSpecs.closed_io.send @method }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/write.rb b/spec/ruby/core/io/shared/write.rb index aa6b3eedeb..542d20d2a4 100644 --- a/spec/ruby/core/io/shared/write.rb +++ b/spec/ruby/core/io/shared/write.rb @@ -23,7 +23,7 @@ describe :io_write, shared: true do end it "checks if the file is writable if writing more than zero bytes" do - lambda { @readonly_file.send(@method, "abcde") }.should raise_error(IOError) + -> { @readonly_file.send(@method, "abcde") }.should raise_error(IOError) end it "returns the number of bytes written" do @@ -50,7 +50,7 @@ describe :io_write, shared: true do it "does not warn if called after IO#read" do @file.read(5) - lambda { @file.send(@method, "fghij") }.should_not complain + -> { @file.send(@method, "fghij") }.should_not complain end it "writes to the current position after IO#read" do @@ -66,7 +66,17 @@ describe :io_write, shared: true do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send(@method, "hello") }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method, "hello") }.should raise_error(IOError) + end + + it "does not modify the passed argument" do + File.open(@filename, "w") do |f| + f.set_encoding(Encoding::IBM437) + # A character whose codepoint differs between UTF-8 and IBM437 + f.write "ƒ\n".freeze + end + + File.binread(@filename).bytes.should == [159, 10] end describe "on a pipe" do diff --git a/spec/ruby/core/io/stat_spec.rb b/spec/ruby/core/io/stat_spec.rb index d46d4105ca..58eba02b8f 100644 --- a/spec/ruby/core/io/stat_spec.rb +++ b/spec/ruby/core/io/stat_spec.rb @@ -11,7 +11,7 @@ describe "IO#stat" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.stat }.should raise_error(IOError) + -> { IOSpecs.closed_io.stat }.should raise_error(IOError) end it "returns a File::Stat object for the stream" do diff --git a/spec/ruby/core/io/sync_spec.rb b/spec/ruby/core/io/sync_spec.rb index c8c1c5a57e..993b7ee244 100644 --- a/spec/ruby/core/io/sync_spec.rb +++ b/spec/ruby/core/io/sync_spec.rb @@ -27,7 +27,7 @@ describe "IO#sync=" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.sync = true }.should raise_error(IOError) + -> { IOSpecs.closed_io.sync = true }.should raise_error(IOError) end end @@ -45,7 +45,7 @@ describe "IO#sync" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.sync }.should raise_error(IOError) + -> { IOSpecs.closed_io.sync }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/sysopen_spec.rb b/spec/ruby/core/io/sysopen_spec.rb index 91f70c3ca9..4607d13687 100644 --- a/spec/ruby/core/io/sysopen_spec.rb +++ b/spec/ruby/core/io/sysopen_spec.rb @@ -33,7 +33,7 @@ describe "IO.sysopen" do end it "accepts a mode as second argument" do - lambda { @fd = IO.sysopen(@filename, "w") }.should_not raise_error + -> { @fd = IO.sysopen(@filename, "w") }.should_not raise_error @fd.should_not equal(0) end diff --git a/spec/ruby/core/io/sysread_spec.rb b/spec/ruby/core/io/sysread_spec.rb index 4062620367..024200efea 100644 --- a/spec/ruby/core/io/sysread_spec.rb +++ b/spec/ruby/core/io/sysread_spec.rb @@ -58,13 +58,13 @@ describe "IO#sysread on a file" do it "does not raise error if called after IO#read followed by IO#write" do @file.read(5) @file.write("abcde") - lambda { @file.sysread(5) }.should_not raise_error(IOError) + -> { @file.sysread(5) }.should_not raise_error(IOError) end it "does not raise error if called after IO#read followed by IO#syswrite" do @file.read(5) @file.syswrite("abcde") - lambda { @file.sysread(5) }.should_not raise_error(IOError) + -> { @file.sysread(5) }.should_not raise_error(IOError) end it "reads updated content after the flushed buffered IO#write" do @@ -77,7 +77,7 @@ describe "IO#sysread on a file" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.sysread(5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.sysread(5) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/sysseek_spec.rb b/spec/ruby/core/io/sysseek_spec.rb index 84e0a1a4ac..df894734e3 100644 --- a/spec/ruby/core/io/sysseek_spec.rb +++ b/spec/ruby/core/io/sysseek_spec.rb @@ -23,7 +23,7 @@ describe "IO#sysseek" do it "raises an error when called after buffered reads" do @io.readline - lambda { @io.sysseek(-5, IO::SEEK_CUR) }.should raise_error(IOError) + -> { @io.sysseek(-5, IO::SEEK_CUR) }.should raise_error(IOError) end it "moves the read position relative to the start with SEEK_SET" do @@ -36,7 +36,7 @@ describe "IO#sysseek" do # this is the safest way of checking the EOF when # sys-* methods are invoked - lambda { @io.sysread(1) }.should raise_error(EOFError) + -> { @io.sysread(1) }.should raise_error(EOFError) @io.sysseek(-25, IO::SEEK_END) @io.sysread(7).should == "cinco.\n" diff --git a/spec/ruby/core/io/syswrite_spec.rb b/spec/ruby/core/io/syswrite_spec.rb index a4dc8328aa..a28cc62174 100644 --- a/spec/ruby/core/io/syswrite_spec.rb +++ b/spec/ruby/core/io/syswrite_spec.rb @@ -31,13 +31,13 @@ describe "IO#syswrite on a file" do it "warns if called immediately after a buffered IO#write" do @file.write("abcde") - lambda { @file.syswrite("fghij") }.should complain(/syswrite/) + -> { @file.syswrite("fghij") }.should complain(/syswrite/) end it "does not warn if called after IO#write with intervening IO#sysread" do @file.syswrite("abcde") @file.sysread(5) - lambda { @file.syswrite("fghij") }.should_not complain + -> { @file.syswrite("fghij") }.should_not complain end it "writes to the actual file position when called after buffered IO#read" do diff --git a/spec/ruby/core/io/to_i_spec.rb b/spec/ruby/core/io/to_i_spec.rb index 7cd9e170d2..acf138c663 100644 --- a/spec/ruby/core/io/to_i_spec.rb +++ b/spec/ruby/core/io/to_i_spec.rb @@ -7,6 +7,6 @@ describe "IO#to_i" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.to_i }.should raise_error(IOError) + -> { IOSpecs.closed_io.to_i }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/try_convert_spec.rb b/spec/ruby/core/io/try_convert_spec.rb index cff56ba618..5fbd10b6fa 100644 --- a/spec/ruby/core/io/try_convert_spec.rb +++ b/spec/ruby/core/io/try_convert_spec.rb @@ -38,12 +38,12 @@ describe "IO.try_convert" do it "raises a TypeError if the object does not return an IO from #to_io" do obj = mock("io") obj.should_receive(:to_io).and_return("io") - lambda { IO.try_convert(obj) }.should raise_error(TypeError) + -> { IO.try_convert(obj) }.should raise_error(TypeError) end it "propagates an exception raised by #to_io" do obj = mock("io") obj.should_receive(:to_io).and_raise(TypeError.new) - lambda{ IO.try_convert(obj) }.should raise_error(TypeError) + ->{ IO.try_convert(obj) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/io/ungetbyte_spec.rb b/spec/ruby/core/io/ungetbyte_spec.rb index f5f9a11be1..1971dee534 100644 --- a/spec/ruby/core/io/ungetbyte_spec.rb +++ b/spec/ruby/core/io/ungetbyte_spec.rb @@ -43,7 +43,7 @@ describe "IO#ungetbyte" do end it "... but not for Bignum argument (eh?)" do - lambda { + -> { @io.ungetbyte(0x4f7574206f6620636861722072616e6765) }.should raise_error(TypeError) end @@ -52,7 +52,7 @@ describe "IO#ungetbyte" do ruby_version_is '2.6'...'2.6.1' do it "is an RangeError if the integer is not in 8bit" do for i in [4095, 0x4f7574206f6620636861722072616e6765] do - lambda { @io.ungetbyte(i) }.should raise_error(RangeError) + -> { @io.ungetbyte(i) }.should raise_error(RangeError) end end end @@ -68,6 +68,6 @@ describe "IO#ungetbyte" do it "raises an IOError if the IO is closed" do @io.close - lambda { @io.ungetbyte(42) }.should raise_error(IOError) + -> { @io.ungetbyte(42) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb index 7d090d0e5d..34d4caf745 100644 --- a/spec/ruby/core/io/ungetc_spec.rb +++ b/spec/ruby/core/io/ungetc_spec.rb @@ -100,7 +100,7 @@ describe "IO#ungetc" do it "makes subsequent unbuffered operations to raise IOError" do @io.getc @io.ungetc(100) - lambda { @io.sysread(1) }.should raise_error(IOError) + -> { @io.sysread(1) }.should raise_error(IOError) end it "does not affect the stream and returns nil when passed nil" do @@ -130,6 +130,6 @@ describe "IO#ungetc" do it "raises IOError on closed stream" do @io.getc @io.close - lambda { @io.ungetc(100) }.should raise_error(IOError) + -> { @io.ungetc(100) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/write_nonblock_spec.rb b/spec/ruby/core/io/write_nonblock_spec.rb index 285d1af376..18adfcfc4a 100644 --- a/spec/ruby/core/io/write_nonblock_spec.rb +++ b/spec/ruby/core/io/write_nonblock_spec.rb @@ -32,7 +32,7 @@ platform_is_not :windows do end it "checks if the file is writable if writing zero bytes" do - lambda { + -> { @readonly_file.write_nonblock("") }.should raise_error(IOError) end @@ -54,7 +54,7 @@ describe 'IO#write_nonblock' do end it "raises an exception extending IO::WaitWritable when the write would block" do - lambda { + -> { loop { @write.write_nonblock('a' * 10_000) } }.should raise_error(IO::WaitWritable) { |e| platform_is_not :windows do diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb index 5fb5cc7013..b28b582019 100644 --- a/spec/ruby/core/io/write_spec.rb +++ b/spec/ruby/core/io/write_spec.rb @@ -21,7 +21,7 @@ describe "IO#write on a file" do end it "does not check if the file is writable if writing zero bytes" do - lambda { @readonly_file.write("") }.should_not raise_error + -> { @readonly_file.write("") }.should_not raise_error end it "returns a length of 0 when writing a blank string" do @@ -59,7 +59,7 @@ describe "IO#write on a file" do # pack "\xFEhi" to avoid utf-8 conflict xFEhi = ([254].pack('C*') + 'hi').force_encoding('utf-8') File.open(@filename, "w", encoding: Encoding::US_ASCII) do |file| - lambda { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError) + -> { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError) end end |