diff options
Diffstat (limited to 'spec/ruby/core/kernel/printf_spec.rb')
| -rw-r--r-- | spec/ruby/core/kernel/printf_spec.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/spec/ruby/core/kernel/printf_spec.rb b/spec/ruby/core/kernel/printf_spec.rb index d1743dbcde..61bf955c25 100644 --- a/spec/ruby/core/kernel/printf_spec.rb +++ b/spec/ruby/core/kernel/printf_spec.rb @@ -31,6 +31,13 @@ describe "Kernel.printf" do object.should_receive(:write).with("string") Kernel.printf(object, "%s", "string") end + + it "calls #to_str to convert the format object to a String" do + object = mock('format string') + object.should_receive(:to_str).and_return("to_str: %i") + $stdout.should_receive(:write).with("to_str: 42") + Kernel.printf($stdout, object, 42) + end end describe "Kernel.printf" do @@ -41,7 +48,7 @@ describe "Kernel.printf" do context "io is specified" do it_behaves_like :kernel_sprintf, -> format, *args { - io = StringIO.new + io = StringIO.new(+"") Kernel.printf(io, format, *args) io.string } @@ -51,7 +58,7 @@ describe "Kernel.printf" do it_behaves_like :kernel_sprintf, -> format, *args { stdout = $stdout begin - $stdout = io = StringIO.new + $stdout = io = StringIO.new(+"") Kernel.printf(format, *args) io.string ensure |
