FAQ
I have a catalyst application that I've been working on for some time (it is pretty big now), and am finally trying to write tests for it. The application runs error free when run in its entirety. But I can't get Model Tests to run. My Model is DBI based, where each DSN has a MyApp::Model::DSN parent module and then there are MyApp::Model::DSN::Table child modules which contain the methods relevant to each table. I would like to access my model methods in a manner similar to how I do in an application:

is( $BoPeep->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep. There are 3 sheep in BoPeeps flock' ) ;

Search Discussions

  • Tomas Doran at Aug 13, 2011 at 10:01 am

    On 12 Aug 2011, at 18:44, John Karr wrote:
    I have a catalyst application that I've been working on for some
    time (it is pretty big now), and am finally trying to write tests
    for it. The application runs error free when run in its entirety.
    But I can't get Model Tests to run. My Model is DBI based, where
    each DSN has a MyApp::Model::DSN parent module and then there are
    MyApp::Model::DSN::Table child modules which contain the methods
    relevant to each table. I would like to access my model methods in a
    manner similar to how I do in an application:

    is( $BoPeep->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep.
    There are 3 sheep in BoPeeps flock' ) ;
    You appear to have forgotten the question.

    Cheers
    t0m
  • Tomas Doran at Aug 13, 2011 at 10:05 am
    On 13 Aug 2011, at 11:01, Tomas Doran wrote:
    On 12 Aug 2011, at 18:44, John Karr wrote:


    I have a catalyst application that I've been working on for some
    time (it is pretty big now), and am finally trying to write tests
    for it. The application runs error free when run in its entirety.
    But I can't get Model Tests to run. My Model is DBI based, where
    each DSN has a MyApp::Model::DSN parent module and then there are
    MyApp::Model::DSN::Table child modules which contain the methods
    relevant to each table. I would like to access my model methods in
    a manner similar to how I do in an application:

    is( $BoPeep->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep.
    There are 3 sheep in BoPeeps flock' ) ;
    You appear to have forgotten the question.
    Sorry, didn't mean to be quite so brief - lack of caffeine..

    I meant that you need to show us what code you're trying, and how it
    doesn't work for you (along with a couple of the classes under test).

    Otherwise you have a un undefined problem with something undefined,
    and I'm afraid the best answer you're going to get, without someone
    solving the halting problem, or my becoming psychic, is "you're doing
    it wrong".

    Cheers
    t0m
  • Eden Cardim at Aug 15, 2011 at 11:13 am
    "John" == John Karr writes:
    John> I have a catalyst application that I've been working on for
    John> some time (it is pretty big now), and am finally trying to
    John> write tests for it. The application runs error free when run
    John> in its entirety. But I can't get Model Tests to run. My Model
    John> is DBI based, where each DSN has a MyApp::Model::DSN parent
    John> module and then there are MyApp::Model::DSN::Table child
    John> modules which contain the methods relevant to each table. I
    John> would like to access my model methods in a manner similar to
    John> how I do in an application:

    John> is( $BoPeep->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep. There are 3 sheep in BoPeeps flock' ) ;

    Can you tell us exactly what goes wrong when you run that? It should
    work just fine.

    --
    Eden Cardim
    Code Monkey http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://blog.edencardim.com/ http://www.shadowcat.co.uk/servers/
    http://twitter.com/#!/edenc
  • John Karr at Aug 15, 2011 at 7:50 pm
    ========================
    # Parent Model
    package BoPeep::Model::DBI;

    use strict; use warnings;
    use DBIx::Simple ;
    use parent 'Catalyst::Model::DBI';

    __PACKAGE__->config( .. stuff .. );

    use Moose ;
    has db=>(The following is
    is =>'ro',
    isa=>'DBIx::Simple',
    lazy_build=> 1, );
    sub _build_db {
    my $self = shift ;
    return DBIx::Simple->connect($self->dbh); }

    =========================
    # Method Model
    package BoPeep::Model::DBI::Flock;
    use Moose;
    use namespace::autoclean;
    extends 'BoPeep::Model::DBI';

    sub CountSheep {
    my $self = shift ;
    my $q = 'SELECT COUNT (*) FROM flock' ;
    my $countedsheep = $self->db->query( $q )->list ;
    return $countedsheep ; }

    =========================
    ## Finally an attempt at a test script looks something like:

    use strict; use warnings; use Carp::Always ;
    use Test::More;

    BEGIN { use_ok 'BoPeep::Model::DBI::Flock' }
    use BoPeep::Model::DBI::Flock ;
    my $BoPeep = BoPeep::Model::DBI::Flock->new() ||
    die "cant make new object"; #also tried connect
    ok( $BoPeep, 'Object evaluates as true!' );
    is( $BoPeep->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep. There are 3 sheep in BoPeeps flock' ) ;

    ##############################

    The use statement(s) are successful. If I comment script after use, it runs.
    Looked at Catalyst::Test docs but it doesn't seem relevant here?

    The error from trying to create the new instance is something like:
    [info] BoPeep powered by Catalyst 5.80033
    t/model_BoPeep_Flock.t .. 1/? Can't call method "log" on an undefined value at /.../perl5/.../Catalyst/Model/DBI.pm line 58
    Catalyst::Model::DBI::new('BoPeep::Model::DBI::Flock') called at t/model_BoPeep_Flock.t line 13
  • Eden Cardim at Sep 5, 2011 at 11:37 am
    "John" == John Karr writes:
    John> I have a catalyst application that I've been working on for
    John> some time (it is pretty big now), and am finally trying to
    John> write tests for it. The application runs error free when run
    John> in its entirety. But I can't get Model Tests to run. My Model
    John> is DBI based, where each DSN has a MyApp::Model::DSN parent
    John> module and then there are MyApp::Model::DSN::Table child
    John> modules which contain the methods relevant to each table. I
    John> would like to access my model methods in a manner similar to
    John> how I do in an application:

    John> is( $BoPeep->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep. There are 3 sheep in BoPeeps flock' ) ;

    use MyApp;
    is( MyApp->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep. There are 3 sheep in BoPeeps flock' ) ;

    The above snippet should work, assuming the CountSheep() method is in place.

    --
    Eden Cardim
    Code Monkey http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://blog.edencardim.com/ http://www.shadowcat.co.uk/servers/
    http://twitter.com/#!/edenc
  • John Karr at Sep 5, 2011 at 11:56 pm
    Thanks Eric -- I had found and posted the solution when the mailing list server was behaving erratically and people may have missed the message.

    When I set the problem aside and looked at it after a few days my mistake was obvious.

    http://lists.scsys.co.uk/pipermail/catalyst/2011-August/027503.html


    -----Original Message-----
    From: Eden Cardim
    Sent: Monday, September 05, 2011 7:38 AM
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] Model Testing Problems.

    ......

    use MyApp;
    is( MyApp->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep. There are 3 sheep in BoPeeps flock' ) ;

    The above snippet should work, assuming the CountSheep() method is in place.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedAug 12, '11 at 5:44p
activeSep 5, '11 at 11:56p
posts7
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase