Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# for Amon2
# spy on render method
sub render_spec {
my ($cb, $req, $spec) = @_;
my $template;
my $param;
no warnings qw/redefine once/;
my $render = *Amon2::Web::render;
# for capture arguments of render method
local *MyApp::Web::render = sub {
(undef, $template, $param) = @_;
$render->(@_);
};
my $res = $cb->($req);
return $spec->($res, $template, $param);
}
subtest "/my/ render user name" => sub {
my $app = Plack::Util::load_psgi 'app.psgi';
test_psgi
app => $app,
client => sub {
my $cb = shift;
my $req = create_request(
method => 'GET',
url => "http://localhost/my/",
);
render_spec $cb, $req => sub {
my ($res, $template, $param) = @_;
is $res->code, 200;
is $template, 'tmpl/my/index.html';
is_deeply $param, { name => "koba04" };
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.