Created
November 6, 2013 14:53
-
-
Save koba04/7337292 to your computer and use it in GitHub Desktop.
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
# 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); | |
} |
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
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