diff options
Diffstat (limited to 'spec/ruby/library/stringio/each_char_spec.rb')
| -rw-r--r-- | spec/ruby/library/stringio/each_char_spec.rb | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/spec/ruby/library/stringio/each_char_spec.rb b/spec/ruby/library/stringio/each_char_spec.rb index 14b2f09a17..1db80c7d07 100644 --- a/spec/ruby/library/stringio/each_char_spec.rb +++ b/spec/ruby/library/stringio/each_char_spec.rb @@ -1,11 +1,38 @@ require_relative '../../spec_helper' require 'stringio' -require_relative 'shared/each_char' describe "StringIO#each_char" do - it_behaves_like :stringio_each_char, :each_char + before :each do + @io = StringIO.new("xyz äöü") + end + + it "yields each character code in turn" do + seen = [] + @io.each_char { |c| seen << c } + seen.should == ["x", "y", "z", " ", "ä", "ö", "ü"] + end + + it "returns self" do + @io.each_char {}.should.equal?(@io) + end + + it "returns an Enumerator when passed no block" do + enum = @io.each_char + enum.instance_of?(Enumerator).should == true + + seen = [] + enum.each { |c| seen << c } + seen.should == ["x", "y", "z", " ", "ä", "ö", "ü"] + end end describe "StringIO#each_char when self is not readable" do - it_behaves_like :stringio_each_char_not_readable, :each_char + it "raises an IOError" do + io = StringIO.new(+"xyz", "w") + -> { io.each_char { |b| b } }.should.raise(IOError) + + io = StringIO.new("xyz") + io.close_read + -> { io.each_char { |b| b } }.should.raise(IOError) + end end |
