M
Mark Volkmann
I wrote a unit test for a method that writes to stdout. I got it to
work, but I'm not sure my approach was the best. Is there a more
recommended way to do this?
# Create a String with a singleton write method
# that allows it to take the place of stdout.
actual =3D '''
def actual.write(data); self << data; end
old_stdout, $stdout =3D $stdout, actual
# Invoke method to test that writes to stdout.
$stdout =3D old_stdout # restore stdout
work, but I'm not sure my approach was the best. Is there a more
recommended way to do this?
# Create a String with a singleton write method
# that allows it to take the place of stdout.
actual =3D '''
def actual.write(data); self << data; end
old_stdout, $stdout =3D $stdout, actual
# Invoke method to test that writes to stdout.
$stdout =3D old_stdout # restore stdout