FAQ
Attached is a patch which adds a new '-mech' flag to the
script/create.pl program

It changes the generated test-file, so that instead of testing this...
***
BEGIN { use_ok 'Catalyst::Test', 'myapp' }
BEGIN { use_ok 'testfoo::Controller::Login' }

ok( request('login')->is_success, 'Request should succeed' );
***

It instead tests...
***
BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst', 'myapp' }

ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'created mech object' );
$mech->get_ok( 'http://localhost/login' );
***

The flag does nothing when creating something other than a controller.

The patch is for file "trunk/Catalyst/lib/Catalyst/Helper.pm"
against svn revision 3535

Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Helper.pm.patch
Type: application/octet-stream
Size: 1347 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060303/be43c611/attachment.obj

Search Discussions

  • Sebastian Riedel at Mar 3, 2006 at 12:25 pm

    03.03.2006 11:51 Carl Franks:

    Attached is a patch which adds a new '-mech' flag to the
    script/create.pl program

    It changes the generated test-file, so that instead of testing this...
    ***
    BEGIN { use_ok 'Catalyst::Test', 'myapp' }
    BEGIN { use_ok 'testfoo::Controller::Login' }

    ok( request('login')->is_success, 'Request should succeed' );
    ***

    It instead tests...
    ***
    BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst', 'myapp' }

    ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'created mech
    object' );
    $mech->get_ok( 'http://localhost/login' );
    ***

    The flag does nothing when creating something other than a controller.

    The patch is for file "trunk/Catalyst/lib/Catalyst/Helper.pm"
    against svn revision 3535
    We can't do that, as much as i like Test::WWW::Mechanize, it's not a
    core prereq, so we can't use it in generated code.

    --
    sebastian
  • Matt S Trout at Mar 3, 2006 at 12:37 pm

    On Fri, Mar 03, 2006 at 01:25:25PM +0100, Sebastian Riedel wrote:
    03.03.2006 11:51 Carl Franks:
    Attached is a patch which adds a new '-mech' flag to the
    script/create.pl program

    It changes the generated test-file, so that instead of testing this...
    ***
    BEGIN { use_ok 'Catalyst::Test', 'myapp' }
    BEGIN { use_ok 'testfoo::Controller::Login' }

    ok( request('login')->is_success, 'Request should succeed' );
    ***

    It instead tests...
    ***
    BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst', 'myapp' }

    ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'created mech
    object' );
    $mech->get_ok( 'http://localhost/login' );
    ***

    The flag does nothing when creating something other than a controller.

    The patch is for file "trunk/Catalyst/lib/Catalyst/Helper.pm"
    against svn revision 3535
    We can't do that, as much as i like Test::WWW::Mechanize, it's not a
    core prereq, so we can't use it in generated code.
    Erm, so? Have it check for Test::WWW::Mechanize::Catalyst if the -mech flag
    is passed and bomb out if not, plus emit a warning saying "make sure this
    is in your Makefile.PL".

    Seem reasonable?

    --
    Matt S Trout Offering custom development, consultancy and support
    Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
    Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information

    + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
  • Sebastian Riedel at Mar 3, 2006 at 2:13 pm

    03.03.2006 13:37 Matt S Trout:
    On Fri, Mar 03, 2006 at 01:25:25PM +0100, Sebastian Riedel wrote:

    03.03.2006 11:51 Carl Franks:
    Attached is a patch which adds a new '-mech' flag to the
    script/create.pl program

    It changes the generated test-file, so that instead of testing
    this...
    ***
    BEGIN { use_ok 'Catalyst::Test', 'myapp' }
    BEGIN { use_ok 'testfoo::Controller::Login' }

    ok( request('login')->is_success, 'Request should succeed' );
    ***

    It instead tests...
    ***
    BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst', 'myapp' }

    ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'created mech
    object' );
    $mech->get_ok( 'http://localhost/login' );
    ***

    The flag does nothing when creating something other than a
    controller.

    The patch is for file "trunk/Catalyst/lib/Catalyst/Helper.pm"
    against svn revision 3535
    We can't do that, as much as i like Test::WWW::Mechanize, it's not a
    core prereq, so we can't use it in generated code.
    Erm, so? Have it check for Test::WWW::Mechanize::Catalyst if the -
    mech flag
    is passed and bomb out if not, plus emit a warning saying "make
    sure this
    is in your Makefile.PL".

    Seem reasonable?
    Ok, we could make it a optional prereq (our packagers will hate me
    once again) and eval check for mechanize in the tests.


    --
    sebastian
  • Carl Franks at Mar 3, 2006 at 3:14 pm

    On 03/03/06, Sebastian Riedel wrote:
    Ok, we could make it a optional prereq (our packagers will hate me
    once again) and eval check for mechanize in the tests.
    Ok, here's an updated patch.

    The current behaviour is:
    When running create.pl - the program will die with an appropriate
    error message if T-W-M-C isn't installed.

    When running the test suite - all tests will be skipped if T-W-M-C
    isn't installed.

    There's also a patch for the Makefile.PL prereqs attached.

    Note: I've chosen the following method for the test skip

    our $test_count;
    BEGIN { $test_count = 2 }
    use Test::More tests => $test_count;

    SKIP: {
    eval "use Test::WWW::Mechanize::Catalyst 'myapp'";
    skip 'Test::WWW::Mechanize::Catalyst required', $test_count if $@;
    ...
    }

    This is because I find if you try hard-coding the test count twice, as
    below, they can get out of sync. (I've found this problem on a module
    on cpan before).

    use Test::More tests => 3;

    SKIP: {
    eval "use Test::WWW::Mechanize::Catalyst 'myapp'";
    skip 'Test::WWW::Mechanize::Catalyst required', 3 if $@;
    ...
    }

    It's also preferable to having 'no_plan', because if any further tests
    are added by the app developer, a test count is 'a good thing' :)

    Cheers,
    Carl
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: Makefile.PL.patch
    Type: application/octet-stream
    Size: 351 bytes
    Desc: not available
    Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060303/1774a167/attachment-0002.obj
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: Helper.pm.patch
    Type: application/octet-stream
    Size: 1763 bytes
    Desc: not available
    Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060303/1774a167/attachment-0003.obj
  • Aristotle Pagaltzis at Mar 3, 2006 at 3:41 pm
    * Carl Franks [2006-03-03 16:20]:
    Note: I've chosen the following method for the test skip

    our $test_count;
    BEGIN { $test_count = 2 }
    use Test::More tests => $test_count;

    SKIP: {
    eval "use Test::WWW::Mechanize::Catalyst 'myapp'";
    skip 'Test::WWW::Mechanize::Catalyst required', $test_count if $@;
    ...
    }

    This is because I find if you try hard-coding the test count
    twice, as below, they can get out of sync. (I've found this
    problem on a module on cpan before).
    use Test::More;
    eval 'use Test::WWW::Mechanize::Catalyst qw( myapp )';
    plan $@
    ? skip_all => 'Test::WWW::Mechanize::Catalyst required'
    : tests => 2;

    # ...

    Regards,
    --
    #Aristotle
    *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
    &Just->another->Perl->hacker;
  • Carl Franks at Mar 3, 2006 at 3:50 pm

    On 03/03/06, A. Pagaltzis wrote:
    use Test::More;
    eval 'use Test::WWW::Mechanize::Catalyst qw( myapp )';
    plan $@
    ? skip_all => 'Test::WWW::Mechanize::Catalyst required'
    : tests => 2;
    ooh, I like that

    Sri, you want another patch with that instead? {sigh}

    Carl
  • Sebastian Riedel at Mar 3, 2006 at 4:06 pm

    03.03.2006 16:50 Carl Franks:
    On 03/03/06, A. Pagaltzis wrote:

    use Test::More;
    eval 'use Test::WWW::Mechanize::Catalyst qw( myapp )';
    plan $@
    ? skip_all => 'Test::WWW::Mechanize::Catalyst required'
    : tests => 2;
    ooh, I like that

    Sri, you want another patch with that instead? {sigh}
    No, i've applied the previous one with some changes.

    Btw. it has to be:

    plan $@
    ? ( skip_all => 'Test::WWW::Mechanize::Catalyst required' )
    : ( tests => 2 );


    --
    sebastian
  • Carl Franks at Mar 3, 2006 at 4:20 pm

    On 03/03/06, Sebastian Riedel wrote:
    No, i've applied the previous one with some changes.
    That's cool.

    Here's another minor fix for that (against 3538)

    The line reading "our $test_count;" had accidentally been left in, on
    the end of a [% IF %] line
    (which is needed, to get correct formatting in the final scripts).

    Carl
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: Helper.pm.patch
    Type: application/octet-stream
    Size: 363 bytes
    Desc: not available
    Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060303/51a2d00a/attachment.obj

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMar 3, '06 at 10:51a
activeMar 3, '06 at 4:20p
posts9
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase