[Catalyst] faking $c->user in tests

Daniel McBrearty danielmcbrearty at gmail.com
Sat Jan 13 21:10:36 GMT 2007


it works fine.

when I run with 'make test' though I get a lot of

Use of uninitialized value in pattern match (m//) at
/usr/local/lib/perl5/site_perl/5.8.8/HTTP/Cookies.pm line 45

which seems to be to do with this in HTTP::Cookies

sub add_cookie_header
{
    my $self = shift;
    my $request = shift || return;
    my $url = $request->url;
    my $scheme = $url->scheme;
    unless ($scheme =~ /^https?\z/) {


.
.
.

I don't get this when I do

perl -Ilib t/controller_Admin.t

why? what's the big difference when I do make test? that would make
this method not get an argument all of a sudden?




On 1/13/07, Ash Berlin <ash_cpan at firemirror.com> wrote:
> Daniel McBrearty wrote:
> > heh ... cheers ... think I've sussed it :
> >
> > my $ue = 1;
> > my $username = 'NotAnAdmin';
> > use Test::MockObject;
> > my $user = Test::MockObject->new;
> >
> > $user->mock( 'id',
> >             sub {return $username} );
> >
> > package MyApp;
> >
> > sub user {
> >  return $user;
> > }
> >
> > sub user_exists {
> >  return $ue;
> > }
> >
> > package main;
> > ...
> >
> > at least it looks sane at the mo ...
> >
> >
> > On 1/13/07, Ash Berlin <ash_cpan at firemirror.com> wrote:
> >> Daniel McBrearty wrote:
> >> > in test scripts I am able to (for instance) mess with the config my
> >> doing
> >> >
> >> > my $config = MyApp->config;
> >> > $config->{some_val} = 'test value';
> >> >
> >> >
> >> > given that I am happy that my Authentication code is well tested in
> >> > some other test script, is there a way to somehow bypass it, forcing
> >> > calls to $c->user_exists and $c->user in the module I'm testing to
> >> > return values which I directly control in the test script?
> >> >
> >> > thanks
> >> >
> >> > Daniel
> >> >
> >> >
> >>
> >> Slightly hacky but something like:
> >>
> >> {
> >>    no warnings 'redefine'; # Not sure if this will be needed in this case
> >>    *MyApp::user = sub { return bless {id=>'foo'}, MyApp::UserClass };
> >> }
> >>
> >> Might work. Or it might blow up in your face cos you looked at it funny
> >> - YMMV.
> >>
> >> -ash
>
>
> Yeah that looks reasonable enough
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
>


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



More information about the Catalyst mailing list