Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

2shortplanks (968)

2shortplanks
  (email not shown publicly)
http://2shortplanks.com/
AOL IM: trelane2sp (Add Buddy, Send Message)
Yahoo! ID: trelane2sp (Add User, Send Message)

Mark Fowler has never been the same since he was elected leader of the London Perl Mongers. The strain manifests itself mainly in releasing various [cpan.org] modules [cpan.org] to CPAN, giving talks [2shortplanks.com], and use of the Trelane nick on #london.pm for endless procrastination. Doctors are still seeking a cure.
Wednesday February 05, 2003
01:38 PM

Test::DatabaseRow

[ #10417 ]
Today's been a really odd day. I've been running some stuff that takes more than a couple of hours to do it's thing, so I've been doing odds and ends while waiting for it to return the correct (or incorrect) data. Odds and ends like listing to Colin Powel and releasing modules to CPAN. As I said, an odd day.

The second module Profero has released to CPAN today is Test::DatabaseRow - a module that is used to simply test things in are in your database in a Test::Builder compatible way. In the simplest form it runs some SQL for you and checks that the fields in the first row back meet the criteria of the test.

For example, a simple test for my Buffy database:

  row_ok( sql   => "SELECT * FROM chars WHERE name = 'Buffy'",
          tests => [ mother => "Joyce" ],
          label => "Buffy's mother is Joyce" );

There's a SQL generation routine too (though it's also designed to work well with SQL::Abstract if that's your bag)

  row_ok( table => "chars",
          where => [ name     => "Willow" ],
          tests => [ fullname => "Willow Rosenberg"],
                     addr     => qr/Sunnydale/ ],
          label => "Check Willow's name & she lives in Sunnydale" );

The where and tests when used with an arrayref like in the above examples are designed to dtrt and do the right comparisons (which essentially means '=' tests for where and ==, eq or =~ tests depending on the data for the tests.) You can be explicit if you want though:

row_ok( table => "chars",

         where => { 'like' => { name     => 'Angel%'   },},

         tests => { '=='   => { height   => 6*12+1,
                                born     => 1727           }
                    'eq'   => { fullname => "Liam"         },
                    '=~'   => { addr     => qr/California/ },},

         label => "angel entered okay" );

Hope it's useful. I'm off home to crowd round the electric heater and shoot nasty glances and the knackered boiler.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.