Skip to content

Instantly share code, notes, and snippets.

@rkitover
Created January 29, 2013 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkitover/4666437 to your computer and use it in GitHub Desktop.
Save rkitover/4666437 to your computer and use it in GitHub Desktop.
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