Skip to content

Instantly share code, notes, and snippets.

$t->get_ok('/welcome.json')
->json_content_is(
{ message => 'Unicorns can make cookies with their minds' } );
my $c = Mojo::Client->new;
$c->post_form( 'http://api.webservice.com/accounts' =>
{ name => 'unicorn', career => 'baker', type => 'magical' } );
$t->post_form_ok( 'http://api.webservice.com/accounts' =>
{ name => 'unicorn', career => 'baker', type => 'magical' } )
->status_is(201)
->header_is('content-type' => 'application/json')
->json_content_is( { id => 'uni123', name => 'unicorn' } );
$t->reset_session;
my $tx = $t->tx;
is $tx->res->json->{thiskey} => 'exists';
eq_or_diff $tx->res->json->{arbitrary} => { data => 'structure' };
$t->get_ok(...);
$t->head_ok(...);
$t->put_ok(...);
$t->post_ok(...);
$t->post_form_ok(...);
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<ul>
<li><a href="#sad_unicorns">Sad Unicorns</a></li>
<li><a href="#marshmallow_death">Marshmallow Death</a></li>
<li><a href="http://external.url.com/">Laser Beam Eyes</a></li>
use File::Slurp 'slurp';
use Mojo::DOM;
my $dom = Mojo::DOM->new->parse(slurp 'some.html');
$dom->find('li a')
use File::Slurp 'slurp';
use Mojo::DOM;
my $dom = Mojo::DOM->new->parse(scalar slurp 'some.html');