From: Mike Nelson Date: 2006-06-17T07:44:44+09:00 Subject: Re: Testing and STDOUT Eric Hodel wrote: > Its hidden: > > $ ri StringIO#string Thanks, that's the ticket! For posterity here's what I got now. (I moved the $stdout stuff to the setup and teardown sections so I can use it for the rest of my specifies.) $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'dirs' require 'stringio' context "In an empty directory" do setup do @testing_dir = File.join(File.dirname(__FILE__), '..', '_test_temp') @test_dir = File.join(@testing_dir, 'test_dir') Dir.mkdir @testing_dir @stdout_orig = $stdout $stdout = StringIO.new end teardown do Dir.rmdir @testing_dir #@stdout_orig.puts "testy", $stdout.string, "testy end" $stdout = @stdout_orig end specify "we should be able to create any dir" do Dirs.create_dirs @test_dir Dir[@test_dir].should_not_be_empty Dir.rmdir @test_dir $stdout.string.grep(/Creating #{@test_dir}/).should_not_be_empty end end looks pretty nice now, I love it. This gives, $ spec -f s test/dirs_spec.rb In an empty directory - we should be able to create any dir Finished in 0.000861 seconds 1 context, 1 specification, 0 failures -- Posted via http://www.ruby-forum.com/.