diff options
Diffstat (limited to 'spec/ruby/core/kernel/printf_spec.rb')
-rw-r--r-- | spec/ruby/core/kernel/printf_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/ruby/core/kernel/printf_spec.rb b/spec/ruby/core/kernel/printf_spec.rb index b4c68fa449..ed134027c0 100644 --- a/spec/ruby/core/kernel/printf_spec.rb +++ b/spec/ruby/core/kernel/printf_spec.rb @@ -1,5 +1,7 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) +require File.expand_path('../shared/sprintf', __FILE__) +require "stringio" describe "Kernel#printf" do it "is a private method" do @@ -31,4 +33,29 @@ describe "Kernel.printf" do object.should_receive(:write).with("string") Kernel.printf(object, "%s", "string") end + + describe "formatting" do + context "io is specified" do + it_behaves_like :kernel_sprintf, -> (format, *args) { + io = StringIO.new + printf(io, format, *args) + io.string + } + end + + context "io is not specified" do + it_behaves_like :kernel_sprintf, -> (format, *args) { + stdout = $stdout + + begin + $stdout = io = StringIO.new + printf(format, *args) + io.string + ensure + $stdout = stdout + end + } + end + end end + |