Skip to content

Commit f05b7df

Browse files
committed
Spec the resulting encoding with StringIO#initialize
1 parent 8b6ceb9 commit f05b7df

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

spec/ruby/library/stringio/initialize_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,27 @@
183183
@io.string.should == ""
184184
end
185185
end
186+
187+
describe "StringIO#initialize sets the encoding to" do
188+
before :each do
189+
@external = Encoding.default_external
190+
Encoding.default_external = Encoding::ISO_8859_2
191+
end
192+
193+
after :each do
194+
Encoding.default_external = @external
195+
end
196+
197+
it "Encoding.default_external when passed no arguments" do
198+
io = StringIO.new
199+
io.external_encoding.should == Encoding::ISO_8859_2
200+
io.string.encoding.should == Encoding::ISO_8859_2
201+
end
202+
203+
it "the same as the encoding of the String when passed a String" do
204+
s = ''.force_encoding(Encoding::EUC_JP)
205+
io = StringIO.new(s)
206+
io.external_encoding.should == Encoding::EUC_JP
207+
io.string.encoding.should == Encoding::EUC_JP
208+
end
209+
end

0 commit comments

Comments
 (0)