summaryrefslogtreecommitdiff
path: root/spec/ruby/core/io/write_nonblock_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/io/write_nonblock_spec.rb')
-rw-r--r--spec/ruby/core/io/write_nonblock_spec.rb48
1 files changed, 34 insertions, 14 deletions
diff --git a/spec/ruby/core/io/write_nonblock_spec.rb b/spec/ruby/core/io/write_nonblock_spec.rb
index a6a263e931..a6bd43c058 100644
--- a/spec/ruby/core/io/write_nonblock_spec.rb
+++ b/spec/ruby/core/io/write_nonblock_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/write', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/write'
# See https://bugs.ruby-lang.org/issues/5954#note-5
platform_is_not :windows do
@@ -31,13 +31,26 @@ platform_is_not :windows do
end
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_nonblock("ƒ".freeze)
+ end
+
+ File.binread(@filename).bytes.should == [198, 146]
+ end
+
it "checks if the file is writable if writing zero bytes" do
- lambda { @readonly_file.write_nonblock("") }.should raise_error
+ -> {
+ @readonly_file.write_nonblock("")
+ }.should.raise(IOError)
end
end
describe "IO#write_nonblock" do
it_behaves_like :io_write, :write_nonblock
+ it_behaves_like :io_write_no_transcode, :write_nonblock
end
end
@@ -52,25 +65,32 @@ 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|
+ }.should.raise(IO::WaitWritable) { |e|
platform_is_not :windows do
- e.should be_kind_of(Errno::EAGAIN)
+ e.should.is_a?(Errno::EAGAIN)
end
platform_is :windows do
- e.should be_kind_of(Errno::EWOULDBLOCK)
+ e.should.is_a?(Errno::EWOULDBLOCK)
end
}
end
- ruby_version_is "2.3" do
- context "when exception option is set to false" do
- it "returns :wait_writable when the operation would block" do
- loop { break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable }
- 1.should == 1
- end
+ context "when exception option is set to false" do
+ it "returns :wait_writable when the operation would block" do
+ loop {
+ break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable
+ }
+ @write.write_nonblock("a" * 10_000, exception: false).should == :wait_writable
end
end
+ platform_is_not :windows do
+ it 'sets the IO in nonblock mode' do
+ require 'io/nonblock'
+ @write.write_nonblock('a')
+ @write.should.nonblock?
+ end
+ end
end