Skip to content

Commit

Permalink
even more logging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 31, 2013
1 parent ba7830b commit fee38fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions t/mojolicious/app.t
Expand Up @@ -180,9 +180,19 @@ $t->get_ok('/syntax_error/foo')->status_is(500)
->content_like(qr/Missing right curly/);

# Foo::syntaxerror (syntax error in template)
my $log = '';
my $cb = $t->app->log->on(message => sub { $log .= pop });
$t->get_ok('/foo/syntaxerror')->status_is(500)
->header_is(Server => 'Mojolicious (Perl)')
->content_like(qr/Missing right curly/);
like $log, qr/Rendering template "syntaxerror.html.epl"./, 'right message';
like $log, qr/Missing right curly/, 'right message';
like $log, qr/Template "exception.development.html.ep" not found./,
'right message';
like $log, qr/Rendering cached template "exception.html.epl"./,
'right message';
like $log, qr/500 Internal Server Error/, 'right message';
$t->app->log->unsubscribe(message => $cb);

# Exceptional::this_one_dies (action dies)
$t->get_ok('/exceptional/this_one_dies')->status_is(500)
Expand Down Expand Up @@ -445,9 +455,21 @@ $t->get_ok('/staged')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is('Go away!');

# MojoliciousTestController::Foo::suspended
$log = '';
$cb = $t->app->log->on(message => sub { $log .= pop });
$t->get_ok('/suspended')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Suspended' => '0, 1, 1, 2')->content_is('Have fun!');
like $log, qr!GET "/suspended".!, 'right message';
like $log,
qr/Routing to controller "MojoliciousTest::Foo" and action "suspended"./,
'right message';
like $log, qr/Routing to controller "MojoliciousTest::Foo" and action "fun"./,
'right message';
like $log, qr!Rendering template "foo/fun.html.ep" from DATA section.!,
'right message';
like $log, qr/200 OK/, 'right message';
$t->app->log->unsubscribe(message => $cb);

# MojoliciousTest::Foo::config
$t->get_ok('/stash_config')->status_is(200)
Expand Down
3 changes: 3 additions & 0 deletions t/mojolicious/group_lite_app.t
Expand Up @@ -195,8 +195,11 @@ my $log = '';
my $cb = $t->app->log->on(message => sub { $log .= pop });
$t->get_ok('/suspended?ok=1')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is('suspended!');
like $log, qr!GET "/suspended".!, 'right message';
like $log, qr/Routing to a callback./, 'right message';
like $log, qr/Nothing has been rendered, expecting delayed response./,
'right message';
like $log, qr/Rendering inline template./, 'right message';
$t->app->log->unsubscribe(message => $cb);

# Suspended bridge (stopped)
Expand Down
5 changes: 4 additions & 1 deletion t/mojolicious/lib/MojoliciousTest/Foo.pm
Expand Up @@ -6,7 +6,7 @@ sub config {
$self->render(text => $self->stash('config')->{test});
}

sub fun { shift->render(text => 'Have fun!') }
sub fun { shift->render }

sub index {
my $self = shift;
Expand Down Expand Up @@ -87,6 +87,9 @@ sub withlayout { shift->stash(template => 'WithGreenLayout') }
1;
__DATA__
@@ foo/fun.html.ep
Have fun!\
@@ just/some/template.html.epl
Development template with high precedence.
Expand Down

0 comments on commit fee38fb

Please sign in to comment.