[Catalyst] unit testing with MockObject

Christopher H. Laco claco at chrislaco.com
Sat Jun 3 17:26:17 CEST 2006


Daniel McBrearty wrote:
> that doesn't seem to do it either.
> 
> here's the top of my test file :
> 
> use strict;
> use warnings;
> use Test::WWW::Mechanize::Catalyst 'Engoi';
> use Test::MockObject;
> use Test::More tests => 3;
> use Data::Dumper;
> 
> BEGIN {
>     my $mock = Test::MockObject->new;
>     #Engoi->components->{'Controller::Public'} = $mock;
>     $mock->fake_module('Engoi::Controller::Public');
>     $mock->set_true('home');
>     use_ok('Catalyst::Test', 'Engoi');
> }
> 
> I've tried various combinationsof those lines in the BEGIN block ...
> 
> anyone got any ideas? or some example code that works?
> 
> 
> 
> On 6/3/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
>> Daniel McBrearty wrote:
>>> I am doing this :
>>>
>>> my $mock = Test::MockObject->new;
>>> $mock->fake_module('Engoi::Controller::Public');
>>> $mock->set_true('home');
>>>
>>> almost the first thing in the test file.
>>>
>>> Later I do a get on /public/home, but the method in the real
>>> controller still gets called.
>> Engoi->components->{Controller::Public} = $mock;
>>
>> maybe

Off the top of my head, with no other thoughts, does running an app usin
Catalyst::Test run the app in a different process than where the .t test
file actually runs? If so, then any mocking you do in the .t test file
won't be seen by the running Catalyst app.


I could be way off base there.
-=Chris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060603/c544e13b/attachment.pgp 


More information about the Catalyst mailing list