Mat Schaffer wrote:
> setting $stdio to a StringIO seems to be pretty productive.

I assume you mean $stdout.

This is what I have thus far with $stdout. It seems to be capturing the 
output, but I'm having trouble getting back the output from StringIO 
later. Not sure what I'm missing. This is what I have.


$:.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
  end

  teardown do
    Dir.rmdir @testing_dir
  end

  specify "we should be able to create any dir" do
    puts "\n========================test first==================\n"
    stdout_orig = $stdout
    $stdout = StringIO.new
    puts "\n========================test first end==================\n"

    Dirs.create_dirs @test_dir
    Dir[@test_dir].should_not_be_empty
    Dir.rmdir @test_dir

    puts "\n========================test ==================\n"
    #$stdout.to_a.should_not_be_empty
    stdout_orig.puts "testy", $stdout.readlines, "testy end"
    $stdout.readlines.grep(/Creating/).should_not_be_empty
    $stdout = stdout_orig
    puts "\n========================test end ==================\n"
  end

end


gives,

In an empty directory

========================test first==================
testy
testy end
- we should be able to create any dir (FAILED - 1)

1)
ExpectationNotMetError in 'In an empty directory we should be able to 
create any dir'
[] should not be empty
/home/mike/projects/ruby/rspace/test/dirs_spec.rb:29:in `we should be 
able to create any dir'

Finished in 0.001164 seconds

1 context, 1 specification, 1 failure

-- 
Posted via http://www.ruby-forum.com/.