mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
io.c: write a newline together
* io.c (rb_io_puts): write a newline together at once for each argument. based on the patch by rohitpaulk (Rohit Kuruvilla) at [ruby-core:83508]. [Feature #14042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
50a99a7679
commit
635d0822cd
3 changed files with 32 additions and 10 deletions
|
@ -43,18 +43,16 @@ describe "IO#puts" do
|
|||
object.should_receive(:method_missing).with(:to_ary)
|
||||
object.should_receive(:to_s).and_return("#<Object:0x...>")
|
||||
|
||||
@io.should_receive(:write).with("#<Object:0x...>")
|
||||
@io.should_receive(:write).with("\n")
|
||||
@io.puts(object).should == nil
|
||||
ScratchPad.recorded.should == "#<Object:0x...>\n"
|
||||
end
|
||||
|
||||
it "calls :to_ary before writing non-string objects" do
|
||||
object = mock('hola')
|
||||
object.should_receive(:to_ary).and_return(["hola"])
|
||||
|
||||
@io.should_receive(:write).with("hola")
|
||||
@io.should_receive(:write).with("\n")
|
||||
@io.puts(object).should == nil
|
||||
ScratchPad.recorded.should == "hola\n"
|
||||
end
|
||||
|
||||
it "calls :to_s before writing non-string objects that don't respond to :to_ary" do
|
||||
|
@ -69,9 +67,8 @@ describe "IO#puts" do
|
|||
object = mock('hola')
|
||||
object.should_receive(:to_s).and_return(false)
|
||||
|
||||
@io.should_receive(:write).with(object.inspect.split(" ")[0] + ">")
|
||||
@io.should_receive(:write).with("\n")
|
||||
@io.puts(object).should == nil
|
||||
ScratchPad.recorded.should == object.inspect.split(" ")[0] + ">\n"
|
||||
end
|
||||
|
||||
it "writes each arg if given several" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue