Baby-Step-Moose

It is almost programing day here in the Moose-Pen

I left off form my last post with a name-space change from 'SQL' to 'DBI' and the first think I have to do today is come up with an initial test case to work against. The usual first test is you simple does it load test like 00_load.t


#!perl
use Test::More tests => 1;
BEGIN {
    use_ok('Database::Accessor') || print "Bail out!";
}
1;
that I used in Database::Accessor. Now for my Driver I and not creating a stand alone module but a Moose Role that Accessor will use, so I have to use a variation on the above;

BEGIN {
–   use_ok('Database::Accessor') || print "Bail out!";
++  require_ok( 'Database::Accessor' )||print "Bail out!";
++  require_ok( 'DBI' )||print "Bail out!";
}
That is the first part done I need both Database::Accessor and DBI install if I am going to test anything. Now testing a Moose Role can be tricky but luckily we have MooseX::Test::Role to help us out. You may remember this MooseX as I used it in this post when I was playing with 20_dad_load.t. What I think I need need next then is

++my $dad_role = consuming_class("Database::Accessor::Driver::DBI");
The above does not really test my class as I could have just about anything in I wanted in the 'Database::Accessor::Driver::DBI' role as long as it had at least;

Package  Database::Accessor::Driver::DBI;
use Moose::Role;
So the first thing I want to do is check and ensure that the I am actually consuming the 'Database::Accessor::Roles::Driver' with that role. To accomplish that I have to use Moose::Util function 'does_role' to check and see if I used the correct role to start. Now the full test now looks like this

#!perl
use MooseX::Test::Role;
use Moose::Util qw(does_role);
use Test::More tests => 1;

BEGIN {
require_ok('Database::Accessor') || print "Bail out!";
require_ok('DBI') || print "Bail out!";
}

my $dad_role = consuming_class("Database::Accessor::Driver::DBI");

if ( does_role( $dad_role, 'Database::Accessor::Roles::Driver' ) ) {
pass('Does Driver Role');
}
else {
fail('Does Driver Role');
}
1;


Well that is my first test done now just need to start writing some code. But that is another post.

Twin-Moose-Calves.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations