Samuel Tesla wrote:

>I'm writing some cookie-handling code, and I want to write the unit
>tests first.  I've got a good idea how I'm going to do it, but I
>wanted to know if there was a better way (or an example I could look
>at).
>
>I was planning on mocking up a CGI object to return my CGI::Cookie
>when queried, then (somehow) causing that CGI object to be the one
>that my code uses.  However, I'm not very fluent in how to hack the
>list of loaded modules (which I'm accustomed to doing in Perl).
>
>Could anybody point me in a direction?
>  
>
One thing you can do is to setup the code which you're unit testing to 
accept a cgi object as a parameter.  Then, in your tests you can 
instantiate a CGI object, put the cookies you want into it and then hand 
it off to the code that you're testing.  Of course, if all that code 
does is handle cookies, you don't even need a CGI object.  You can pass 
in any object that responds to "cookies" with a Hash-like thing.  Ruby 
is nice for doing mock objects, since all you have to do is respond to 
the right messages (but not worry about object type).

Chad