~ubuntu-branches/ubuntu/trusty/libtest-roo-perl/trusty-proposed

« back to all changes in this revision

Viewing changes to examples/cookbook/sqlite-confirm.t

  • Committer: Package Import Robot
  • Author(s): gregor herrmann
  • Date: 2014-01-14 19:25:11 UTC
  • Revision ID: package-import@ubuntu.com-20140114192511-9ycl4dc1zgamfnek
Tags: upstream-1.002
ImportĀ upstreamĀ versionĀ 1.002

Show diffs side-by-side

added added

removed removed

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