Skip to content

Instantly share code, notes, and snippets.

@koba04
Created November 6, 2013 14:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koba04/7337292 to your computer and use it in GitHub Desktop.
Save koba04/7337292 to your computer and use it in GitHub Desktop.
# 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