On Sat, Jul 31, 2010 at 5:38 PM, Fernando Guillen
<fguillen.mail / gmail.com> wrote:
> Hi people,
>
> I have an application that download emails from an email account an
> process them.
>
> What I would like to do is to mock the mail download petition and not
> process the real mails but an array of mails I have for this propos.
>
> This is the precise situation: I have this:
>
> [code]
>  гۺݬ ۺݬ ۺ >    >   >  
>  
> [/code]
>
> I would like to have a mock that if on my test call to
>
> => Net::POP3.start( opts[:server], port, opts[:user], opts[:pass] ) do
> |pop|
>
> Not any mailing petition is done but the body of the method is still
> working but not with real mails but with an array of fake mails like
> this:
>
> => mails = [ File.read('/dir/mail1.raw_mail'),
> File.read('/dir/mail2.raw_mail')]
>
> Is this possible?.. am I completely lost?.. is there any better way to
> do this?

One option would be to change the start method of Net::POP3 to do
exactly what you describe.
Remember that Ruby is open and you can redefine any method on any
class. You can always alias the method start before changing it, so
you can revert to the original definition after the test.

Jesus.