[Dancer-users] Best way to test using Test::WWW::Mechanize?

Michael Alan Dorman mdorman at ironicdesign.com
Tue Feb 22 16:35:52 CET 2011


Hey, all,

I'm starting a new app, and want to be able to build my tests
concurrently.  In prior projects I've used T::W::M::Catalyst, and want
to use it to handle testing for my new app.

I guess my first question is whether ::PSGI is the most appropriate
flavor to use---it would appear to me to be, but I suppose I could have
missed a ::Dancer flavor that hasn't been released or something?

Anyway, proceeding on that basis, I have gotten it working, but I have a
question about what I had to do to get it to work versus what I expected
to work.

So, this worked (using the output of 'dancer -a Foo'):

----->8-----
#!/usr/bin/perl
use Dancer qw{:syntax};
use Foo;
use Test::More tests => 2;
require Test::WWW::Mechanize::PSGI;
set apphandler => 'PSGI';
my $test = Test::WWW::Mechanize::PSGI->new (app => do ("bin/app.pl"));
$test->get_ok ('/') or diag $test->content;
$test->content_contains ('Tutorial');
-----8<-----

The thing that confuses and annoys me is the need to use 'do'---mostly
because I don't quite understand why I need it.  I tried:

----->8-----
#!/usr/bin/perl
use Dancer;
use Foo;
use Test::More tests => 2;
require Test::WWW::Mechanize::PSGI;
set apphandler => 'PSGI';
my $test = Test::WWW::Mechanize::PSGI->new (app => dance);
$test->get_ok ('/') or diag $test->content;
$test->content_contains ('Tutorial');
-----8<-----

and it failed with a 404.  Since that pretty much recapitulates the
content of bin/app.pl, and the result of do ("bin/app.pl") should be the
return value of dance, I'm a little confused.  Any enlightenment?

Regardless, other than this small roadbump, I'm rather enjoying Dancer
as a development platform.  Thanks for all your efforts.

Mike.



More information about the Dancer-users mailing list