summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringio/putc_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/stringio/putc_spec.rb')
-rw-r--r--spec/ruby/library/stringio/putc_spec.rb25
1 files changed, 20 insertions, 5 deletions
diff --git a/spec/ruby/library/stringio/putc_spec.rb b/spec/ruby/library/stringio/putc_spec.rb
index 223b3523e5..9f1ac8ffb2 100644
--- a/spec/ruby/library/stringio/putc_spec.rb
+++ b/spec/ruby/library/stringio/putc_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "StringIO#putc when passed [String]" do
before :each do
- @io = StringIO.new('example')
+ @io = StringIO.new(+'example')
end
it "overwrites the character at the current position" do
@@ -35,11 +35,26 @@ describe "StringIO#putc when passed [String]" do
@io.putc("t")
@io.pos.should == 3
end
+
+ it "handles concurrent writes correctly" do
+ @io = StringIO.new
+ n = 8
+ go = false
+ threads = n.times.map { |i|
+ Thread.new {
+ Thread.pass until go
+ @io.putc i.to_s
+ }
+ }
+ go = true
+ threads.each(&:join)
+ @io.string.size.should == n
+ end
end
describe "StringIO#putc when passed [Object]" do
before :each do
- @io = StringIO.new('example')
+ @io = StringIO.new(+'example')
end
it "it writes the passed Integer % 256 to self" do
@@ -70,7 +85,7 @@ end
describe "StringIO#putc when in append mode" do
it "appends to the end of self" do
- io = StringIO.new("test", "a")
+ io = StringIO.new(+"test", "a")
io.putc(?t)
io.string.should == "testt"
end
@@ -78,10 +93,10 @@ end
describe "StringIO#putc when self is not writable" do
it "raises an IOError" do
- io = StringIO.new("test", "r")
+ io = StringIO.new(+"test", "r")
-> { io.putc(?a) }.should raise_error(IOError)
- io = StringIO.new("test")
+ io = StringIO.new(+"test")
io.close_write
-> { io.putc("t") }.should raise_error(IOError)
end