On 5/10/05, Vincent Foley <vfoley / gmail.com> wrote:
> Hi everyone,
> 
> I recently wrote a small user application called RJournal[1], and for
> the next release I would love to have much more unit tests than I
> currently do.  However, my problem is that most methods I would like to
> test have side effects.  For example, I have a method called
> LiveJournalClient#post which, as its name says, posts a new message to
> LiveJournal.  How can I test that this worked without filling up a
> journal?

Depending on how your method actually posts messages, you could write
stubs for calls it makes and test them for validity. It would be better to
create a throw-away journal to post to, though. Im guessing these journals
are somewhere online?

> Similarily, when the application starts, it checks to see if
> the config file exists; if it does not, it should create it and add the
> parameters to it: how can I test this if the file already exists?  And
> without nuking everything I already have.

If you use unix, you can chroot before starting your app, and then it
will be safe to use absolute pathnames to find/create your config file.
Otherwise, you could add an option that lets you specify the
location of the file for testing purposes.

> Ryan Levengood suggested in another thread that I use mock objects for
> my testing purposes, but I don't understand clearly how they work.

Mock objects are simply objects with the same api as the real object, but
which output some kind of message or log file as to what is happening to them
instead of doing real work.

> If anyone could actually write a test or two for my application, so
> that I can see how to do it, I would be very grateful.

It might be worth doing it yourself just to get a feel for what has to be done.
Im sure theres a million test frameworks written in Ruby already.

-- 
spooq