use Mojo::Base -strict, -signatures; use Test::Mojo; use Test::More; use Mojo::File; use Mojo::Util qw/url_escape/; my $t = Test::Mojo->new( Mojo::File->new('/path/to/app.pl') ); $t->get_ok('/')->status_is(200)->content_like(qr/\bUser List\b/); $t->get_ok('/user/1')->status_is(404); $t->get_ok('/user/2') ->header_is(location => '/user/' . url_escape 'John H'); $t->get_ok('/user/3')->status_is(404); $t->get_ok('/user/4') ->header_is(location => '/user/' . url_escape 'Sam A'); $t->get_ok('/user/5')->status_is(404); $t->get_ok('/user/6')->status_is(404); $t->get_ok('/user/2/') # trailing slash ->header_is(location => '/user/' . url_escape 'John H'); $t->get_ok('/user/John H')->status_is(200) ->content_like(qr/\bThis is John H's Page\b/); $t->get_ok('/user/Sam A')->status_is(200) ->content_like(qr/\bThis is Sam A's Page\b/); $t->get_ok('/user/John Doe')->status_is(404); done_testing;