[Catalyst] Testing View

Yao Wang S3115360 at student.rmit.edu.au
Sat Apr 19 16:04:43 BST 2008


Hi,

Thanks Matt. Now i know i have used wrong way to call a method in the controller.

However ,the reason i use $c->prepare is for unit testing. I have seen  Catalyst::Test and Test::WWW::Mechanize::Catalyst, i think they are the testing tools for application, not for unit testing. When i do the unit testing, i need to pass $c and some other params to the methods.
So can anybody tell me how to create this kind of $c for testing only ?

Thanks,
Yao


-----Original Message-----
From: Matt S Trout <dbix-class at trout.me.uk>
To: The elegant MVC web framework <catalyst at lists.scsys.co.uk>
Date: Fri, 18 Apr 2008 20:11:22 +0100
Subject: Re: [Catalyst] Testing View

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/

_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/





More information about the Catalyst mailing list