Dragos Trif Dragos Trif - 23 days ago 8
Perl Question

Falling to configure Test::DBIx::Class::Schema for a Dancer2 to app

I,m trying to run a sanity test for my

Dancer2
app schema using
Test::DBIx::Class::Schema.

I created a
test.t
and placed in my main app directory (not inside the
/t
folder). The file looks like this:

#!/usr/bin/perl

use Test::More 'no_plan';
use Test::DBIx::Class::Schema;
use Dancer2::Test app => ['PearlBee'];
use lib 'lib';
use lib::PearlBee::Model::Schema;

use strict;
use warnings;

# the order is important


BEGIN {
use_ok 'Test::DBIx::Class::Schema';
#use_ok 'lib::PearlBee::Model::Schema';
use_ok 'Dancer2::Test', app => 'PearlBee';
use_ok 'lib::PearlBee::Model::Schema';# apps => ['PearlBee'];

#
#use_ok 'DBICx::TestDatabase';
}

#my $schema = DBICx::TestDatabase->new('lib::PearlBee::Model::Schema');


my $schematest = Test::DBIx::Class::Schema->new(
{
# required
dsn => 'dbi:mysql:PearlBee;host=localhost;', # or use schema option
namespace => 'lib::PearlBee::Model::Schema',
moniker => 'user',
# optional
username => 'root',
password => '1',
glue => 'Result',
#test_missing => 1,
}
);

$schematest->methods(
{
columns => [
qw[
id
salt

]
],

resultsets => [
qw[ User
]
],
}
);

$schematest->run_tests();


I crashes with the following output:

Can't locate object method "connect" via package "lib::PearlBee::Model::Schema"


Please help me to make sense out of this.

Answer

These lines look interesting:

use lib 'lib';
use lib::PearlBee::Model::Schema;

The first one seems ok. I can see why you'd want to add 'lib' to @INC. But having done that, I'd expect the second line to be:

use PearlBee::Model::Schema;

It seems very unlikely that you'd need that lib:: on the front of the module name. But perhaps your directory structure is more complex that I'm assuming. Where is the PearlBee schema module?

Update: Also note that the latest version of the Dancer2::Test documentation says this:

DEPRECATED. Please use Plack::Test instead as shown in the SYNOPSIS!

This module will warn for a while until we actually remove it. This is to provide enough time to fully remove it from your system.

I suggest you follow that advice.