[Catalyst] unit testing with MockObject

Daniel McBrearty danielmcbrearty at gmail.com
Sat Jun 3 17:46:05 CEST 2006


now I have this :

BEGIN {
    my $mock = Test::MockObject->new;
    $mock->fake_module('Engoi::Controller::Public');
    $mock->set_true('home');
    use_ok('Catalyst::Test', 'Engoi');
    Engoi->components->{'Controller::Public'} = $mock;
}

but I still have my errors as before, and the mock object is not being
used by Cat.


On 6/3/06, Daniel McBrearty <danielmcbrearty at gmail.com> wrote:
> something fishy in that BEGIN block, I get this when I do make test:
>
> [Sat Jun  3 17:29:07 2006] [catalyst] [info] engoi powered by Catalyst 5.67
> t/01app................ok 1/3Called UNIVERSAL::can() as a function,
> not a method at /usr/local/lib/perl/5.8.7/Template/Provider.pm line
> 275
> Called UNIVERSAL::can() as a function, not a method at
> /usr/local/lib/perl/5.8.7/Template/Provider.pm line 275
> Called UNIVERSAL::can() as a function, not a method at
> /usr/local/lib/perl/5.8.7/Template/Iterator.pm line 78
>
> (and loads more like that ... )
>
>
> On 6/3/06, Christopher H. Laco <claco at chrislaco.com> 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.
> >
> >
> > I could be way off base there.
> > -=Chris
> >
> >
> >
> > _______________________________________________
> > 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
>


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



More information about the Catalyst mailing list