I want to be able to unit/test an output with the method 'puts'. Here's
a small example of what I'm trying to achieve:
puts is a convenience function. It's really $stdout.write() etc.
So use fileHandle.write(), and then pass in a handle to an IO-stream, or a
temporary file, into your routine.
Yes, that means you pass more crap around. Unit testing powerfully decouples
your code, such that you no longer couple even with convenience objects like
$stdout.
Use util_capture from the ZenTest gem. You get two StringIO objects back from calling util_capture that hold the contents of $stdout and $stderr in the block:
Nice. Does this also prevent the output from being dumped to the
console during the test?
···
On 9/8/06, Eric Hodel <drbrain@segment7.net> wrote:
Use util_capture from the ZenTest gem. You get two StringIO objects
back from calling util_capture that hold the contents of $stdout and
$stderr in the block:
out, err = util_capture do
Foo.new.output
end
--
Regards,
John Wilger
-----------
Alice came to a fork in the road. "Which road do I take?" she asked.
"Where do you want to go?" responded the Cheshire cat.
"I don't know," Alice answered.
"Then," said the cat, "it doesn't matter."
- Lewis Carrol, Alice in Wonderland
Thanks everybody and thanks to Eric, this is exactly what I needed.
···
On Saturday, September 09, 2006, at 8:51 AM, Eric Hodel wrote:
On Sep 8, 2006, at 12:29 PM, Eric Boucher wrote:
I want to be able to unit/test an output with the method 'puts'. > Here's
a small example of what I'm trying to achieve:
Use util_capture from the ZenTest gem. You get two StringIO objects
back from calling util_capture that hold the contents of $stdout and
$stderr in the block:
On 9/8/06, Eric Hodel <drbrain@segment7.net> wrote:
Use util_capture from the ZenTest gem. You get two StringIO objects
back from calling util_capture that hold the contents of $stdout and
$stderr in the block:
out, err = util_capture do
Foo.new.output
end
Nice. Does this also prevent the output from being dumped to the
console during the test?
--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant