[Catalyst] unit testing with MockObject
Daniel McBrearty
danielmcbrearty at gmail.com
Sun Jun 4 10:59:33 CEST 2006
> 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.
D
--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131
More information about the Catalyst
mailing list