From: Alex Young Date: 2006-08-06T15:13:10+09:00 Subject: Re: How to redirect a string to stdin within code? Logan Capaldo wrote: > > On Aug 5, 2006, at 6:00 PM, Christian Seifert wrote: > >> Hello all, I am trying to create a unit test for a class that reads >> input from stdin (ie. the user enters his name when starting the >> class). I would like to write a unit test that provides the input via >> a string. something like: >> >> input = "myname" >> $stdin = input >> start my class that I would like to test >> >> Any help is greatly appreciated. >> >> Christian >> > > require 'stringio' > > input = StringIO.new("myname") > > $stdin = input But: alex@pandora:~$ irb irb(main):001:0> require 'stringio' => true irb(main):002:0> input = StringIO.new("myname") => # irb(main):003:0> $stdin = input => # /usr/lib/ruby/1.8/irb/input-method.rb:97: [BUG] Segmentation fault ruby 1.8.4 (2005-12-24) [i486-linux] Aborted This is on Ubuntu Breezy. Any idea why that happens? -- Alex