[Catalyst] unit testing with MockObject
Matt S Trout
dbix-class at trout.me.uk
Sat Jun 3 17:37:03 CEST 2006
Christopher H. Laco wrote:
> 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.
Not by default, no.
The problem is that Daniel needs to do the ->components->{...} = *after*
he's loaded Catalyst::Test for Engoi, since until that point the
appclass components hash isn't there to be modified.
More information about the Catalyst
mailing list