[Catalyst] Testing View

Matt S Trout dbix-class at trout.me.uk
Fri Apr 18 20:11:22 BST 2008

On Thu, Apr 17, 2008 at 02:56:49PM +1000, Yao Wang wrote:
> Dear Friends,
> I have just started working on a project using Catalyst. I am trying my hand at testing and got the following issue :(
> I have created the following test file:
> my $c = MyApp -> prepare();
> MyApp::Controller::MyController::MyAction(undef, $c);
> ok($c->stash->{template} eq $expected_template_name, "comparing template returned");
> Now, all seemed to work fine till i realized that its better to explicitly
> forward $c to MyApp::View::TT rather than doing in the end method. But after adding this line to my controller action i got this error:
> "Modification of non-creatable array value attempted, subscript -1 at
> /usr/lib/perl5/vendor_perl/5.8.8/Catalyst/Dispatcher.pm line 186."
> I guess this is happening because $c->stash->template does not exist anymore?
> Any way to get around this problem.

use Catalyst::Test 'MyApp';
use Test::WWW::Mechanize::Catalyst 'MyApp';

You can't just call ->prepare with no engine, bypass the entire dispatch
setup and then expect the dispatcher to work.

Also, a controller is an object. Calling methods as subroutines is
-just- -wrong-.

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list