summaryrefslogtreecommitdiff
path: root/spec/ruby/core/io/write_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/io/write_spec.rb')
-rw-r--r--spec/ruby/core/io/write_spec.rb21
1 files changed, 14 insertions, 7 deletions
diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb
index 4a26f8dbaf..1a745ba012 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
- -> { @readonly_file.write("") }.should_not raise_error
+ -> { @readonly_file.write("") }.should_not.raise
end
before :each do
@@ -102,11 +102,18 @@ describe "IO#write on a file" do
File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
end
+ it "ignores the 'bom|' prefix" do
+ File.open(@filename, "w", encoding: 'bom|utf-8') do |file|
+ file.write("hi")
+ end
+ File.binread(@filename).should == "hi"
+ end
+
it "raises a invalid byte sequence error if invalid bytes are being written" 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|
- -> { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError)
+ -> { file.write(xFEhi) }.should.raise(Encoding::InvalidByteSequenceError)
end
end
@@ -150,7 +157,7 @@ describe "IO.write" do
it "requires mode to be specified in :open_args" do
-> {
IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true}])
- }.should raise_error(IOError, "not opened for writing")
+ }.should.raise(IOError, "not opened for writing")
IO.write(@filename, 'hi', open_args: ["w", {encoding: Encoding::UTF_32LE, binmode: true}]).should == 8
IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true, mode: "w"}]).should == 8
@@ -159,7 +166,7 @@ describe "IO.write" do
it "requires mode to be specified in :open_args even if flags option passed" do
-> {
IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true, flags: File::CREAT}])
- }.should raise_error(IOError, "not opened for writing")
+ }.should.raise(IOError, "not opened for writing")
IO.write(@filename, 'hi', open_args: ["w", {encoding: Encoding::UTF_32LE, binmode: true, flags: File::CREAT}]).should == 8
IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true, flags: File::CREAT, mode: "w"}]).should == 8
@@ -172,11 +179,11 @@ describe "IO.write" do
it "raises ArgumentError if encoding is specified in mode parameter and is given as :encoding option" do
-> {
IO.write(@filename, 'hi', mode: "w:UTF-16LE:UTF-16BE", encoding: Encoding::UTF_32LE)
- }.should raise_error(ArgumentError, "encoding specified twice")
+ }.should.raise(ArgumentError, "encoding specified twice")
-> {
IO.write(@filename, 'hi', mode: "w:UTF-16BE", encoding: Encoding::UTF_32LE)
- }.should raise_error(ArgumentError, "encoding specified twice")
+ }.should.raise(ArgumentError, "encoding specified twice")
end
it "writes the file with the permissions in the :perm parameter" do
@@ -220,7 +227,7 @@ describe "IO.write" do
end
end
- ruby_version_is "3.3" do
+ ruby_version_is ""..."4.0" do
# https://bugs.ruby-lang.org/issues/19630
it "warns about deprecation given a path with a pipe" do
-> {