Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

json_like for Test::Mojo

View json_like.pl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/env perl
 
use Test::More;
use Test::Mojo;
use Mojolicious::Lite;
 
my $json_like = sub {
my ($t, $p, $regex, $desc) = @_;
$desc ||= "json_like $regex";
local $Test::Builder::Level = $Test::Builder::Level + 1;
$t->success( like( $t->tx->res->json($p), $regex, $desc ) );
};
 
any '/' => sub {
shift->render( json => { quote => 'Why not Zoidberg?' } );
};
 
my $t = Test::Mojo->new;
$t->get_ok('/')
->$json_like( '/quote' => qr/Zoidberg/ )
->or(sub{ diag 'I guess not Zoidberg' });
 
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.