dhosek has asked for the wisdom of the Perl Monks concerning the following question:

OK, here's the situation, I've got a module which is passed a DSN and makes its own dbh. But for testing purposes, I want to be able to mock the handle. However, I can't seem to find any contextual example of using DBD::Mock::Session which I would think would do the job.
use DBD::Mock;

my $session = DBD::Mock::Session->new(
    'testing_session' => (
        {
            statement => "SHOW TABLES",
            results   => ['table1', 'table2']
        },
    )
);

use Module::Being::Tested;

Module::Being::Tested::function($dsn); 
I can't seem to get the session to work, though. Should I be passing the $session variable to something somehow?

Update: I found what I need--sort of. It seems that DBD::Mock requires the tester to have access to the DBI object to do the calls. Is there any workaround for that? I'd prefer to pass in DSN/username/password rather than a DBI object for my module...

Donald Hosek, Tech Lead at oversee.net
L.A. perl people, we're hiring.

Replies are listed 'Best First'.
Re: DBD::Mock problem
by dragonchild (Archbishop) on Apr 11, 2008 at 20:18 UTC
    Send me (rkinyon@cpan.org) a failing test and I'll see what can be done. I don't use that feature myself (it was added as a patch when stvn was maintaining it). I think the point was that the $dbh was reused across many sessions. *shrugs*

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?