[Catalyst] unit testing with MockObject

Daniel McBrearty danielmcbrearty at gmail.com
Sun Jun 4 14:04:42 CEST 2006


good question ... I have an auto action in the root controller which
redirects unless the request is to public/home OR (some other stuff).

Maybe I should move that action into Root.


On 6/4/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
> Daniel McBrearty wrote:
> >  > You can't dispatch to a controller you're mocking unless you mock the
> >> internal dispatch stuff as well ...
> >
> > (testcode)
> >
> > BEGIN { use_ok('Catalyst::Test', 'Engoi'); }
> > my $mock = Test::MockObject->new;
> > $mock->set_true('home');
> > Engoi->components->{'Engoi::Controller::Public'} = $mock;
> >
> > clearSession();
> > my $mech = Test::WWW::Mechanize::Catalyst->new;
> > $mech->requests_redirectable( [] );
> >
> > $r = $mech->get($dr.'public/home');
> > $l = $r->header('location');
> > ok( !$r->is_redirect, 'no redirect to natlang with no session');
> >
> > (/testcode)
> >
> > and this works apart form the error ...
> >
> > Obviously I don't want to be having to simulate all the internals of a
> > Controller to test ... so I try to use Test::MockObject::Extends
> > instead (I only want to override one method, right ...?):
> >
> > (newtestcode)
> > BEGIN { use_ok('Catalyst::Test', 'Engoi'); }
> >
> > my $mock = Test::MockObject::Extends->new(Engoi->components->{'Engoi::Controller::Public'}
> > );
> > $mock->set_true('home');
> > (/newtestcode)
> >
> > but now the MockObject stops working ...
> >
> > maybe cat loads actions when the script starts, whatever
> > MockObject::Extends does is just ignored I guess?
> >
> > what am I doing wrong ... seems I am making hard work of something
> > that shouldn't be *that* tough ... is there an easier way to do all
> > this?
> >
> > All I *really* need to do is stub out a method in a controller that I
> > am not testing here, stop it redirecting itself and breaking my tests.
>
> If you're not testing Controller::Public, why are you dispatching a
> request to "public/home" in the first place?
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>


-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131



More information about the Catalyst mailing list