On Fri, Aug 1, 2008 at 5:31 PM, Shadowfirebird <shadowfirebird / gmail.com> wrote:
> Forgive me if this is a stupid question.
>
> (Actually, I know it's a stupid question -- they're the only ones
> worth asking...)
>
> * How do you unit test a method who's job is to interface with the
> outside world?  For example, a method that outputs to a file? *
>
> I've done a lot of coding, but in a dinosaur language -- automated
> unit tests are completely new to me.   I understand how to use
> unit/test; but it seems to me that that's only half the story.  I need
> some suggestions on how to design my code in such a way as it can be
> tested.   Suggestions, anyone?

Usually, mock objects are best for this.  There exist some special
purpose ones, but it is relatively straightforward to put one together
using something like Mocha or Flexmock, both available on RubyForge.
If you are using RSpec, support for mock objects is built in.

-greg

-- 
Killer Ruby PDF Generation named after a magnificent sea creature:
http://github.com/sandal/prawn | Non-tech stuff at:
http://metametta.blogspot.com