Last active
January 2, 2016 04:29
-
-
Save jberger/8251222 to your computer and use it in GitHub Desktop.
json_like for Test::Mojo
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
#!/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