Created
January 29, 2013 18:33
-
-
Save rkitover/4666437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojo::Base -strict; | |
use Test::More; | |
use Mojolicious::Lite; | |
use Test::Mojo; | |
app->hook(around_dispatch => sub { | |
my $orig = shift; | |
my ($c) = @_; | |
my $static_served = $c->app->static->dispatch($c); | |
if (not $static_served) { | |
$c->stash(dynamic => 'dynamic request'); | |
return $orig->(@_); | |
} | |
return $static_served; | |
}); | |
get '/' => sub { my $c = shift; $c->render_text($c->stash->{dynamic}) }; | |
my $t = Test::Mojo->new; | |
# Static file | |
$t->get_ok('/hello.txt')->status_is(200) | |
->content_is("Hello Mojo from a static file!\n"); | |
# dynamic request | |
$t->get_ok('/')->status_is(200) | |
->content_is('dynamic request'); | |
done_testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment