1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
use Test::Roo;
use DBI;
use Path::Tiny;
has tempdir => (
is => 'ro',
clearer => 1,
default => sub { Path::Tiny->tempdir },
);
has dbfile => (
is => 'lazy',
default => sub { shift->tempdir->child('test.sqlite3') },
);
has dbh => ( is => 'lazy', );
sub _build_dbh {
my $self = shift;
DBI->connect(
"dbi:SQLite:dbname=" . $self->dbfile, { RaiseError => 1 }
);
}
before 'setup' => sub {
my $self = shift;
$self->dbh->do("CREATE TABLE f (f1, f2, f3)");
};
after 'teardown' => sub { shift->clear_tempdir };
test 'first' => sub {
my $self = shift;
my $dbh = $self->dbh;
my $sth = $dbh->prepare("INSERT INTO f(f1,f2,f3) VALUES (?,?,?)");
ok( $sth->execute( "one", "two", "three" ), "inserted data" );
my $got = $dbh->selectrow_arrayref("SELECT * FROM f");
is_deeply( $got, [qw/one two three/], "read data" );
};
run_me;
done_testing;
|