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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#!/usr/bin/perl
use strict;
use warnings;
use lib 't/010-resources/';
use Test::More;
use Test::Fatal;
use Plack::Request;
use Plack::Response;
use Web::Machine::FSM;
{
package DieInFinishRequest;
use base 'Web::Machine::Resource';
sub content_types_provided { [{ 'text/html' => 'to_html' }] }
sub to_html { 'foo' }
sub known_methods { [qw[ GET ]] }
sub finish_request {
die "Something bad happened\n";
}
}
my $fsm = Web::Machine::FSM->new();
my @errors;
my $logger = sub { push @errors, @_ };
my $request = Plack::Request->new(
{
REQUEST_METHOD => 'GET',
'psgix.logger' => $logger
}
);
my $r = DieInFinishRequest->new(
request => $request,
response => Plack::Response->new
);
is(
exception { $fsm->run($r) },
undef,
'no exception from resource which throws an error'
);
is_deeply(
\@errors,
[ { level => 'error', message => "Something bad happened\n" } ],
'psgix.logger is called with error message'
);
done_testing;
|