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/shared | |
parent | a06301b103371b0b7da8eaca26ba744961769f99 (diff) |
Update to ruby/spec@875a09e
Diffstat (limited to 'spec/ruby/core/io/shared')
-rw-r--r-- | spec/ruby/core/io/shared/binwrite.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/chars.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/codepoints.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/each.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/new.rb | 48 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/pos.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/readlines.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/tty.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/io/shared/write.rb | 16 |
9 files changed, 57 insertions, 47 deletions
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 |