Testing Your Template

Occasionally you might want to test that $c->view('Whatever')->process is being called with the arguments you expect (usually $c->stash->{template}). Here's what I recommend:

use Catalyst::Test 'MyApp';

my $template;
my $old_process = \&YourApp::View::Whatever::process;
*YourApp::View::Whatever::process = sub {
   my ($self, $c, @args) = @_;
   $template = $c->stash->{template};
   $self->$old_process($c, @args);
}

request('foo');
is $template, 'the_template_for_foo.tt';

Now you can check that running your "foo" action sets $c->stash->{template} to the_template_for_foo.tt.

My tags:
 
Popular tags:
 
Powered by Catalyst
Powered by MojoMojo Hosted by Shadowcat - Managed by Nordaaker